-
-
Save Unskilled/01967483b4f39233aa5943a6c7ce4444 to your computer and use it in GitHub Desktop.
Example of filtering off the Win32_AccountSID association class to convert a SID->User using only WMI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function ConvertFrom-SID { | |
| param ( | |
| [Parameter(Position = 0, Mandatory = $True)] | |
| [String] | |
| [ValidateNotNullOrEmpty()] | |
| $SID | |
| ) | |
| $AccountSIDInstance = Get-CimInstance -ClassName Win32_AccountSID -Filter "Setting = 'Win32_SID.SID=`"$SID`"'" | |
| $Domain = $AccountSIDInstance.Element.Domain | |
| $Name = $AccountSIDInstance.Element.Name | |
| if ($Domain -and $Name) { | |
| "$Domain\$Name" | |
| } | |
| } | |
| # ConvertFrom-SID S-1-5-21-1578066767-49256976-3073566822-1011 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment