Hi Paessler,

I use your script to find currently active users often and it works great, however i was wondering if you have any guidance on how to view the data on who has logged in during a set historical period?

We have over 500 user accounts on our PRTG instance and i am certain almost all of these accounts are unused.

Kindest Samuel


Article Comments

Something like this:

[string] $ConfigurationFilePath = "D:\Applications\PRTG\PRTG Configuration.dat"
   [xml] $configuration = New-Object -TypeName XML;
         $configuration.Load($ConfigurationFilePath)

$prtgUsers = ($configuration.SelectNodes("//nodes/user"))
$prtgBaseDate = [datetime]::parseexact("30.12.1899 00:00:00", 'dd.MM.yyyy HH:mm:ss',[CultureInfo]::InvariantCulture)

$logins = @()


foreach($prtgUser in $prtgUsers){
    
   $lastLogin = $null
   
   try   { [datetime]$lastLogin = $prtgBaseDate.AddDays($prtgUser.data.lastlogin.Trim()) }
   # if we fail to parse the date (because the user has not logged on yet), set it to the PRTG base date
   catch { [datetime]$lastLogin = $prtgBaseDate }

   $logins += [pscustomobject] @{

        ID   = $prtgUser.id
        User = $prtgUser.data.login.InnerText.Trim()
        "Last Login" = $lastLogin
   }
}

$logins | Out-GridView -Title "PRTG Logins"

Modify the path of your configuration file accordingly :) If the account has 1899 as it's last login, he hasn't logged in yet. Should look like this:


PRTG Scheduler | PRTGapi | Feature Requests | WMI Issues | SNMP Issues

Kind regards,
Stephan Linke, Tech Support Team


Oct, 2018 - Permalink

Uh oh

$logins | Out-GridView -Title "PRTG Logins" Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime." At line:7 char:1 + $prtgBaseDate = [datetime]::parseexact("30.12.1899 00:00:00", 'dd.MM. ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : FormatException

43388.6520235648 You cannot call a method on a null-valued expression. At line:16 char:4 + [datetime]$lastLogin = $prtgBaseDate.AddDays($prtgUser.data.lastlo ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression. At line:19 char:4 + $logins += [pscustomobject] @{ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull


Oct, 2018 - Permalink

Hi Sam,

I beg your pardon, I've updated the script with a little bit of try/catch - should work as intended now :)


PRTG Scheduler | PRTGapi | Feature Requests | WMI Issues | SNMP Issues

Kind regards,
Stephan Linke, Tech Support Team


Oct, 2018 - Permalink

Hi Stephan,

Thanks for your ever speedy replies, ISE is still taking issue with the system.datetime and logins = @()

$logins | Out-GridView -Title "PRTG Logins"
Cannot convert null to type "System.DateTime".
At line:14 char:4
+    $lastLogin = $null
+    ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : MetadataError: (:) [], ArgumentTransformationMetadataException
    + FullyQualifiedErrorId : RuntimeException
 
You cannot call a method on a null-valued expression.
At line:20 char:4
+    $logins += [pscustomobject] @{
+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
Cannot convert null to type "System.DateTime".
At line:14 char:4
+    $lastLogin = $null
+    ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : MetadataError: (:) [], ArgumentTransformationMetadataException
    + FullyQualifiedErrorId : RuntimeException
 
You cannot call a method on a null-valued expression.
At line:20 char:4
+    $logins += [pscustomobject] @{
+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Kindest Sam


Oct, 2018 - Permalink

What does $PSVersionTable say?


PRTG Scheduler | PRTGapi | Feature Requests | WMI Issues | SNMP Issues

Kind regards,
Stephan Linke, Tech Support Team


Oct, 2018 - Permalink
Name                           Value                                                                                                                           
----                           -----                                                                                                                           
PSVersion                      5.1.14393.1884                                                                                                                  
PSEdition                      Desktop                                                                                                                         
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                         
BuildVersion                   10.0.14393.1884                                                                                                                 
CLRVersion                     4.0.30319.42000                                                                                                                 
WSManStackVersion              3.0                                                                                                                             
PSRemotingProtocolVersion      2.3                                                                                                                             
SerializationVersion           1.1.0.1

Oct, 2018 - Permalink

Weird. Please open up a support ticket so we can work on this via TeamViewer :) Kindly refer to me.


PRTG Scheduler | PRTGapi | Feature Requests | WMI Issues | SNMP Issues

Kind regards,
Stephan Linke, Tech Support Team


Oct, 2018 - Permalink