$userProfiles = Get-CimInstance-Class Win32_UserProfile | # add property "UserName" that translates SID to username Add-Member-MemberType ScriptProperty -Name UserName -Value { ([Security.Principal.SecurityIdentifier]$this.SID).Translate([Security.Principal.NTAccount]).Value } -PassThru | # create a hash table that uses "Username" as key Group-Object-Property UserName -AsHashTable-AsString
现在可以轻松地转储机器上所有带用户配置文件的用户列表了:
1 2 3 4 5 6 7 8 9 10
PS C:\> $userProfiles.Keys | Sort-Object MYDOMAIN\Administrator MYDOMAIN\User01 MYDOMAIN\User02 MYDOMAIN\User03 MYDOMAIN\User12 NT AUTHORITY\LOCAL SERVICE NT AUTHORITY\NETWORK SERVICE NT AUTHORITY\SYSTEM PC10\User