This question is inspired by this similar question using the C# tag. If I have a Windows SID, and would like to convert it to a readable account name, how can I achieve this using PowerShell instead of C#?
Right now, I have the following code, which retrieves the group memberships for the currently logged on user account:
$Identity = [System.Security.Principal.WindowsIdentity]::GetCurrent();
$Identity.Groups;
The results of the Groups
property does not give me any account names, only SIDs. If I pipe the output from the Groups
property into PowerShell's Get-Member
cmdlet, I can see that the resulting objects are System.Security.Principal.SecurityIdentifier
objects. However, looking at the documentation (and Intellisense) for the Groups
property shows that it is returning an IdentityReferenceCollection
object.
How do I convert these SecurityIdentifier
objects into proper names?