List User Profiles

We’ve received a massive feedback on our tips dealing with user profile management, so we decided to add a couple of additional tips.

WMI can easily enumerate all user profiles on a system but lists only the SID (security identifier), not the plain text user name.

Get-CimInstance -ClassName Win32_UserProfile |
  Out-GridView

To improve this, here is a simple chunk of code that converts SIDs to user names:

$sid = "S-1-5-32-544"
(New-Object System.Security.Principal.SecurityIdentifier($sid)).Translate([System.Security.Principal.NTAccount]).Value

To add a clear text user name to the output of Get-CimInstance, you can use Add-Member and add a ScriptProperty:

Get-CimInstance -ClassName Win32_UserProfile |
    Add-Member -MemberType ScriptProperty -Name UserName -Value { (New-Object System.Security.Principal.SecurityIdentifier($this.Sid)).Translate([System.Security.Principal.NTAccount]).Value } -PassThru |
    Out-GridView

The grid view now shows an additional column called “UserName” with the clear text user name for a given profile.

Are you an experienced professional PowerShell user? Then learning from default course work isn’t your thing. Consider learning the tricks of the trade from one another! Meet the most creative and sophisticated fellow PowerShellers, along with Microsoft PowerShell team members and PowerShell inventor Jeffrey Snover. Attend this years’ PowerShell Conference EU, taking place April 17-20 in Hanover, Germany, for the leading edge. 35 international top speakers, 80 sessions, and security workshops are waiting for you, including two exciting evening events. The conference is limited to 300 delegates. More details at www.psconf.eu.

Twitter This Tip! ReTweet this Tip!

GD Star Rating
loading...