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


Script to see which users have logged in since x ?

Votes:

0

Your Vote:

Up

Down

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

script users webserver

Created on Oct 15, 2018 11:44:50 AM by  Samuel Ashdown (60) 1 1



7 Replies

Votes:

0

Your Vote:

Up

Down

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

Created on Oct 16, 2018 2:09:56 PM by  Stephan Linke [Paessler Support]

Last change on Oct 18, 2018 8:24:32 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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

Created on Oct 18, 2018 7:19:18 AM by  Samuel Ashdown (60) 1 1



Votes:

0

Your Vote:

Up

Down

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

Created on Oct 18, 2018 8:25:03 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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

Created on Oct 18, 2018 9:10:08 AM by  Samuel Ashdown (60) 1 1

Last change on Oct 18, 2018 10:57:34 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

What does $PSVersionTable say?


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

Kind regards,
Stephan Linke, Tech Support Team

Created on Oct 18, 2018 10:57:24 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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

Created on Oct 18, 2018 11:00:21 AM by  Samuel Ashdown (60) 1 1

Last change on Oct 18, 2018 11:10:38 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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

Created on Oct 18, 2018 11:11:12 AM by  Stephan Linke [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.