Skip to content

Instantly share code, notes, and snippets.

@Unskilled
Forked from mattifestation/ConvertFromSID.ps1
Created May 14, 2017 16:11
Show Gist options
  • Select an option

  • Save Unskilled/01967483b4f39233aa5943a6c7ce4444 to your computer and use it in GitHub Desktop.

Select an option

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
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