Tuesday, August 4, 2015

Powershell Script - Get-LocalUsers - Remotely query all local users and details

Here's a lovely script that runs with parallel pipeline queries using the [ADSI] .NET class to remotely query SAM to build nice object outputs which are great for security audits.  Here's some sample output:

PS C:\> 'Server1','Server2' | Get-LocalUsers


Server          : Server1
UserName        : Administrator
Active          : True
PasswordExpired : False
PasswordAgeDays : 16
LastLogin       : 6/3/2015 6:34:27 PM
Groups          : Administrators
Description     : Built-in account for administering the computer/domain

Server          : Server1
UserName        : Guest
Active          : False
PasswordExpired : False
PasswordAgeDays : 0
LastLogin       : 
Groups          : Guests
Description     : Built-in account for guest access to the computer/domain

Server          : Server2
UserName        : Administrator
Active          : True
PasswordExpired : False
PasswordAgeDays : 1
LastLogin       : 3/5/2015 7:28:14 PM
Groups          : Administrators
Description     : Built-in account for administering the computer/domain

Server          : Server2
UserName        : Guest
Active          : False
PasswordExpired : False
PasswordAgeDays : 0
LastLogin       : 
Groups          : Guests
Description     : Built-in account for guest access to the computer/domain


PS C:\> 

And the code:

No comments: