New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


Is there a way to see when all users logged in the last time?

Votes:

0

Your Vote:

Up

Down

I have a lot of users in my PRTG and I'd like to see who's logged in the last time. Is this possible?

active login powershell prtg prtg-login ps1 users

Created on Feb 10, 2017 9:49:38 AM by  Dariusz Gorka [Paessler Support]



16 Replies

Accepted Answer

Votes:

1

Your Vote:

Up

Down

This article applies to PRTG Network Monitor 16 or later

How to Show Last Logins of all PRTG Users

PRTG can show the time when a user logged in the last time, but if you want to cleanup the user database, then this is the fast way to display inactive users.

Please copy and save the script that we provide below as <name>.ps1 and alter the parameters displayed in the head of the script:

-server "<address of PRTG server>" -username "<username of a PRTG Administrator user>" -passhash "<passhash of the PRTG Administrator user>"

Note: You can find the required passhash under Setup | Account Settings | My Account. Click Show Passhash to display it (see PRTG Manual: Account Settings—My Account).

After the execution of the script, you will receive a result like this:

test

The list will allow you to add filter criteria for each column and show all configured users.


Script for post-facelift (version 17.x.35 or later)

#requires -version 4.0
# ___ ___ _____ ___
#| _ \ _ \_   _/ __|
#|  _/   / | || (_ |
#|_| |_|_\ |_| \___|
# Last Login of PRTG Users
# ================================
# This script will show you when which user logged in the last time.  
# ----------------------------
# # # # # # # # # # # # # # # # # # # # # # # # # #
param(
    $server = "http://your-prtg",
    $username = "user",
    $passhash = 3091222222

)

$userlist_url = $server + "/controls/userlist.htm?count=9000&username=" + $username + "&passhash=" + $passhash
$userlist_ids_regex = "<a class=.usermenu. id=.([0-9]+)..href=.edituser.htm.id=[0-9]+.>"
$userlist_names_regex = "<td class=.col-name.data-th=.Obje.t.><a class=.usermenu. id=.[0-9]+. href=.edituser.htm.id=[0-9]+.>(.+)<.a>.+<.td><td class=.col-type.data-th=."

$userlist = Invoke-WebRequest -Uri $userlist_url -UseBasicParsing

$userlist_ids_raw = Select-String $userlist_ids_regex -input $userlist -AllMatches | Foreach {$_.Matches}
$userlist_names_raw = Select-String $userlist_names_regex -input $userlist -AllMatches | Foreach {$_.Matches}

[string[]]$userlist_ids = $null
[string[]]$userlist_names = $null

for($i=0; $i -lt $userlist_ids_raw.Groups.Count; $i++){
    $i++
    $userlist_ids += $userlist_ids_raw.Groups[$i].Value
    $userlist_names += $userlist_names_raw.Groups[$i].Value
}

##########################################################################################

$userlogin_regex = "<div class=.readonlyproperty. >(.+)<.div><.div>"
$userlogin_uname_regex = '<input class="text".*data-rule-required="true" type="text" name="login." id="login." autocomplete="off" value="(.*)".*><.div>'

[string[]]$userlogin_times = $null
[string[]]$userlogin_uname = $null

for($i=0; $i -lt $userlist_ids.Count; $i++){
    $userlogin_url = $server + "/controls/edituser.htm?id=" + $userlist_ids[$i] + "&username=" + $username + "&passhash=" + $passhash
    $userlogin = Invoke-WebRequest -Uri $userlogin_url -UseBasicParsing
    $userlogin_times_raw = Select-String $userlogin_regex -input $userlogin -AllMatches | Foreach {$_.Matches}
    $userlogin_times += $userlogin_times_raw.Groups[1].Value
    $userlogin_uname_raw = Select-String $userlogin_uname_regex -input $userlogin -AllMatches | Foreach {$_.Matches}
    $userlogin_uname += $userlogin_uname_raw.Groups[1].Value
}

$UserList = New-Object System.Collections.ArrayList($null)

if($userlist_ids.Count -eq $userlist_names.Count -and $userlist_ids.Count -eq $userlogin_times.Count -and $userlist_names.Count -eq $userlogin_times.Count -and $userlist_names.Count -eq $userlogin_uname.Count){
    for($i=0; $i -lt $userlist_ids.Count; $i++){
 
        $User = New-Object -TypeName psobject
        Add-Member -InputObject $User -Name ID -Value $userlist_ids[$i] -MemberType NoteProperty
        Add-Member -InputObject $User -Name "User Name" -Value $userlist_names[$i] -MemberType NoteProperty
        Add-Member -InputObject $User -Name "Login Name" -Value $userlogin_uname[$i] -MemberType NoteProperty
        Add-Member -InputObject $User -Name "Last Login" -Value $userlogin_times[$i] -MemberType NoteProperty

        $UserList.add($User) | Out-Null
    }
}

$UserList | Out-GridView -Title "[PRTG] Last Login of all Users"

Script for pre-facelift (versions prior 17.x.35)

#requires -version 4.0
# ___ ___ _____ ___
#| _ \ _ \_   _/ __|
#|  _/   / | || (_ |
#|_| |_|_\ |_| \___|
# Last Login of PRTG Users
# ================================
# This script will show you when which user logged in the last time.  
# ----------------------------
# # # # # # # # # # # # # # # # # # # # # # # # # #
param(
    $server = "http://your-prtg",
    $username = "user",
    $passhash = 3091222222

)

$userlist_url = $server + "/controls/userlist.htm?count=9000&username=" + $username + "&passhash=" + $passhash
$userlist_ids_regex = "<a class=.usermenu. id=.([0-9]+)..href=.edituser.htm.id=[0-9]+.>"
$userlist_names_regex = "<td class=.col-name.><a class=.usermenu. id=.[0-9]+..href=.edituser.htm.id=[0-9]+.>(.+)<.a><.td><td class=.col-type.>"

$userlist = Invoke-WebRequest -Uri $userlist_url -UseBasicParsing

$userlist_ids_raw = Select-String $userlist_ids_regex -input $userlist -AllMatches | Foreach {$_.Matches}
$userlist_names_raw = Select-String $userlist_names_regex -input $userlist -AllMatches | Foreach {$_.Matches}

[string[]]$userlist_ids = $null
[string[]]$userlist_names = $null

for($i=0; $i -lt $userlist_ids_raw.Groups.Count; $i++){
    $i++
    $userlist_ids += $userlist_ids_raw.Groups[$i].Value
    $userlist_names += $userlist_names_raw.Groups[$i].Value
}

##########################################################################################

$userlogin_regex = "<div class=.readonlyproperty. >(.+)<.div><.div>"
$userlogin_uname_regex = '<input class="text".*data-rule-required="true" type="text" name="login." id="login." autocomplete="off" value="(.*)".*><.div>'

[string[]]$userlogin_times = $null
[string[]]$userlogin_uname = $null

for($i=0; $i -lt $userlist_ids.Count; $i++){
    $userlogin_url = $server + "/controls/edituser.htm?id=" + $userlist_ids[$i] + "&username=" + $username + "&passhash=" + $passhash
    $userlogin = Invoke-WebRequest -Uri $userlogin_url -UseBasicParsing
    $userlogin_times_raw = Select-String $userlogin_regex -input $userlogin -AllMatches | Foreach {$_.Matches}
    $userlogin_times += $userlogin_times_raw.Groups[1].Value
    $userlogin_uname_raw = Select-String $userlogin_uname_regex -input $userlogin -AllMatches | Foreach {$_.Matches}
    $userlogin_uname += $userlogin_uname_raw.Groups[1].Value
}

$UserList = New-Object System.Collections.ArrayList($null)

if($userlist_ids.Count -eq $userlist_names.Count -and $userlist_ids.Count -eq $userlogin_times.Count -and $userlist_names.Count -eq $userlogin_times.Count -and $userlist_names.Count -eq $userlogin_uname.Count){
    for($i=0; $i -lt $userlist_ids.Count; $i++){
 
        $User = New-Object -TypeName psobject
        Add-Member -InputObject $User -Name ID -Value $userlist_ids[$i] -MemberType NoteProperty
        Add-Member -InputObject $User -Name "User Name" -Value $userlist_names[$i] -MemberType NoteProperty
        Add-Member -InputObject $User -Name "Login Name" -Value $userlogin_uname[$i] -MemberType NoteProperty
        Add-Member -InputObject $User -Name "Last Login" -Value $userlogin_times[$i] -MemberType NoteProperty

        $UserList.add($User) | Out-Null
    }
}

$UserList | Out-GridView -Title "[PRTG] Last Login of all Users"

Changelog:

13.02.2017 - Added "count=" parameter to the request of the user list, now the script will display more than 50 Users.
15.03.2017 - Added Login-Name Column 08.01.2019 - Changed script to work with facelift

Created on Feb 10, 2017 10:02:06 AM by  Dariusz Gorka [Paessler Support]

Last change on Jan 16, 2019 8:06:40 AM by  Dariusz Gorka [Paessler Support]



Votes:

0

Your Vote:

Up

Down

At the moment, the script doesn´t work. Ich filled the server, username and passhash field, but with the execution I´ve got multiple errors:

Cannot index into a null array. At C:\Users\boet026\Desktop\user.ps1:33 char:5 + $userlist_names += $userlist_names_raw.Groups[$i].Value + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : NullArray

Created on Jan 4, 2019 10:16:49 AM by  Marc Boettcher (0) 1



Votes:

0

Your Vote:

Up

Down

Hi Marc,

Please execute the above script again with all variables set, afterwards execute the following command manually and forward us the error you might get:

Invoke-WebRequest -Uri $userlist_url -UseBasicParsing

Best regards.

Created on Jan 7, 2019 6:23:43 AM by  Dariusz Gorka [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hi Dariusz,

here ist my output

Information posted were deleted by the administrators.

Created on Jan 7, 2019 11:02:42 AM by  Marc Boettcher (0) 1

Last change on Jan 8, 2019 9:40:29 AM by  Dariusz Gorka [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hi Marc,

Seems like we have changed the layout of the tables. The regular expressions weren't working for the post-facelift versions. Please see the initial post where I added a facelift-compatible script.

Best regards.

Created on Jan 8, 2019 9:41:31 AM by  Dariusz Gorka [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hi Dariusz,

thank you for the new code.

that doesn´t work, I´ve got this error:

Cannot index into a null array. At C:\Users\boet026\Desktop\user.ps1:33 char:5 + $userlist_names += $userlist_names_raw.Groups[$i].Value + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : NullArray

Here is the output from

Invoke-WebRequest -Uri $userlist_url -UseBasicParsing

StatusCode : 200 StatusDescription : OK Content : <div class="contexthelpbox prtg-plugin" data-id="id1809916606" data-plugin="contexthelp" data-plugin-function="add" data-plugin-target="#header_help" data-show="true"><div class="helpheader">Benutzerk... RawContent : HTTP/1.1 200 OK Connection: close X-Content-Type-Options: nosniff X-XSS-Protection: 1; mode=block Content-Length: 41390 Cache-Control: no-cache Content-Type: text/html; charset=UTF-8 Date: Wed,... Forms : Headers : {[Connection, close], [X-Content-Type-Options, nosniff], [X-XSS-Protection, 1; mode=block], [Content-Length, 41390]...} Images : {} InputFields : {@{outerHTML=<input id="selectall_2_usertable" title="Alle Einträge auswählen" type="checkbox" class="checkbox tablemultiselectcheckbox selectallasmultiedit" value="-3"/>; tagName=INPUT; id=selectall_2_usertable; title=Alle Einträge auswählen; type=checkbox; class=checkbox tablemultiselectcheckbox selectallasmultiedit; value=-3}} Links : {@{outerHTML=<a href='/help/user_accounts_settings.htm#settings' target='_blank'><b>Help: User Accounts</b></a>; tagName=A; href=/help/user_accounts_settings.htm#settings; target=_blank}, @{outerHTML=<a class="actionbutton add-menu-item" href="/edituser.htm?id=new">Benutzer hinzufügen</a>; tagName=A; class=actionbutton add-menu-item; href=/edituser.htm?id=new}, @{outerHTML=<a class="actionbutton add-menu-item" href="#" onclick="_Prtg.Dialogs.addMultipleUserDialog(); return false;">Mehrere Benutzer hinzufügen</a>; tagName=A; class=actionbutton add-menu-item; href=#; onclick=_Prtg.Dialogs.addMultipleUserDialog(); return false;}, @{outerHTML=<a class="actionbutton add-menu-item" href="/editusergroup.htm?id=new">Benutzergruppe hinzufügen</a>; tagName=A; class=actionbutton add-menu-item; href=/editusergroup.htm?id=new}...} ParsedHtml : RawContentLength : 41390

Created on Jan 9, 2019 5:48:33 AM by  Marc Boettcher (0) 1



Votes:

0

Your Vote:

Up

Down

Hi Marc,

Have you use the first code posted above?

If so, please execute it again and issue the following command afterwards:

$userlist = Invoke-WebRequest -Uri $userlist_url -UseBasicParsing
$userlist.Content

Please post this result as well. :)

Best regards.

Created on Jan 9, 2019 12:32:14 PM by  Dariusz Gorka [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hi, here is my output.

----------------- Please moderate the content, cause of names :)

deleted due to personal data

Created on Jan 14, 2019 7:39:17 AM by  Marc Boettcher (0) 1

Last change on Jan 15, 2019 9:07:43 AM by  Dariusz Gorka [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hi Marc,

I guess I found the issue, your installation uses the German language which is why some fields have other names. Please try the code below and let me know if it works:

#requires -version 4.0
# ___ ___ _____ ___
#| _ \ _ \_   _/ __|
#|  _/   / | || (_ |
#|_| |_|_\ |_| \___|
# Last Login of PRTG Users
# ================================
# This script will show you when which user logged in the last time.  
# ----------------------------
# # # # # # # # # # # # # # # # # # # # # # # # # #
param(
    $server = "http://your-prtg",
    $username = "user",
    $passhash = 3091222222

)

$userlist_url = $server + "/controls/userlist.htm?count=9000&username=" + $username + "&passhash=" + $passhash
$userlist_ids_regex = "<a class=.usermenu. id=.([0-9]+)..href=.edituser.htm.id=[0-9]+.>"
$userlist_names_regex = "<td class=.col-name.data-th=.Obje.t.><a class=.usermenu. id=.[0-9]+. href=.edituser.htm.id=[0-9]+.>(.+)<.a>.+<.td><td class=.col-type.data-th=."

$userlist = Invoke-WebRequest -Uri $userlist_url -UseBasicParsing

$userlist_ids_raw = Select-String $userlist_ids_regex -input $userlist -AllMatches | Foreach {$_.Matches}
$userlist_names_raw = Select-String $userlist_names_regex -input $userlist -AllMatches | Foreach {$_.Matches}

[string[]]$userlist_ids = $null
[string[]]$userlist_names = $null

for($i=0; $i -lt $userlist_ids_raw.Groups.Count; $i++){
    $i++
    $userlist_ids += $userlist_ids_raw.Groups[$i].Value
    $userlist_names += $userlist_names_raw.Groups[$i].Value
}

##########################################################################################

$userlogin_regex = "<div class=.readonlyproperty. >(.+)<.div><.div>"
$userlogin_uname_regex = '<input class="text".*data-rule-required="true" type="text" name="login." id="login." autocomplete="off" value="(.*)".*><.div>'

[string[]]$userlogin_times = $null
[string[]]$userlogin_uname = $null

for($i=0; $i -lt $userlist_ids.Count; $i++){
    $userlogin_url = $server + "/controls/edituser.htm?id=" + $userlist_ids[$i] + "&username=" + $username + "&passhash=" + $passhash
    $userlogin = Invoke-WebRequest -Uri $userlogin_url -UseBasicParsing
    $userlogin_times_raw = Select-String $userlogin_regex -input $userlogin -AllMatches | Foreach {$_.Matches}
    $userlogin_times += $userlogin_times_raw.Groups[1].Value
    $userlogin_uname_raw = Select-String $userlogin_uname_regex -input $userlogin -AllMatches | Foreach {$_.Matches}
    $userlogin_uname += $userlogin_uname_raw.Groups[1].Value
}

$UserList = New-Object System.Collections.ArrayList($null)

if($userlist_ids.Count -eq $userlist_names.Count -and $userlist_ids.Count -eq $userlogin_times.Count -and $userlist_names.Count -eq $userlogin_times.Count -and $userlist_names.Count -eq $userlogin_uname.Count){
    for($i=0; $i -lt $userlist_ids.Count; $i++){
 
        $User = New-Object -TypeName psobject
        Add-Member -InputObject $User -Name ID -Value $userlist_ids[$i] -MemberType NoteProperty
        Add-Member -InputObject $User -Name "User Name" -Value $userlist_names[$i] -MemberType NoteProperty
        Add-Member -InputObject $User -Name "Login Name" -Value $userlogin_uname[$i] -MemberType NoteProperty
        Add-Member -InputObject $User -Name "Last Login" -Value $userlogin_times[$i] -MemberType NoteProperty

        $UserList.add($User) | Out-Null
    }
}

$UserList | Out-GridView -Title "[PRTG] Last Login of all Users"

Created on Jan 15, 2019 9:09:16 AM by  Dariusz Gorka [Paessler Support]

Last change on Jan 16, 2019 8:06:21 AM by  Dariusz Gorka [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Yes, this solution works.

Great Job, thank you! :)

Created on Jan 16, 2019 6:02:08 AM by  Marc Boettcher (0) 1



Votes:

0

Your Vote:

Up

Down

Hallo, danke für Schript. Script liefert keine date. Startet, Endet ohne Fehlel, liefert leider keine Daten. Was kann das sein?

Created on Jan 23, 2019 2:38:15 PM by  Dmitrii Koifman (0) 1



Votes:

0

Your Vote:

Up

Down

Hallo Herr Koifman,

Welches der beiden obigen Scripte haben Sie verwendet? Welche Interface-Sprache ist bei Ihnen eingestellt und am wichtigsten, welche Version setzen Sie ein?

Best regards.

Created on Jan 24, 2019 6:24:45 AM by  Dariusz Gorka [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hallo Dariusz, wir verwenden Version DE V18.4.46.1754. Und ich habe alle vorgeschlagene Scripte probiert. Letzte Script extra für DE Interface liefert auch keine Ergebnisse. Danke

Created on Jan 25, 2019 9:03:15 AM by  Dmitrii Koifman (0) 1



Votes:

0

Your Vote:

Up

Down

Hallo Herr Koifman,

Erhalten Sie denn einen Fehler beim ausführen? Die Parameter haben Sie vor der Ausführung auch angepasst?

Best regards

Created on Jan 25, 2019 9:30:56 AM by  Dariusz Gorka [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hi

I recieve this error:

Invoke-WebRequest : The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
At line:22 char:13
+ $userlist = Invoke-WebRequest -Uri $userlist_url -UseBasicParsing
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

I think it is because my prtg uses HTTPS

any idea how to fix this?

Thanks!

Created on Feb 21, 2019 3:04:35 PM by  sandrada (0) 1

Last change on Feb 21, 2019 7:36:11 PM by  Dariusz Gorka [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hi there,

Please add the following to the beginning of the script, afterwards it should work fine:

if (-not ([System.Management.Automation.PSTypeName]'ServerCertificateValidationCallback').Type)
{
$certCallback = @"
    using System;
    using System.Net;
    using System.Net.Security;
    using System.Security.Cryptography.X509Certificates;
    public class ServerCertificateValidationCallback
    {
        public static void Ignore()
        {
            if(ServicePointManager.ServerCertificateValidationCallback ==null)
            {
                ServicePointManager.ServerCertificateValidationCallback += 
                    delegate
                    (
                        Object obj, 
                        X509Certificate certificate, 
                        X509Chain chain, 
                        SslPolicyErrors errors
                    )
                    {
                        return true;
                    };
            }
        }
    }
"@
    Add-Type $certCallback
 }
[ServerCertificateValidationCallback]::Ignore()

Best regards!

Created on Feb 21, 2019 7:36:41 PM by  Dariusz Gorka [Paessler Support]



Please log in or register to enter your reply.


Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.