Skip to content

Instantly share code, notes, and snippets.

@mattifestation
Created May 14, 2017 15:57
Show Gist options
  • Save mattifestation/cffeecfcee806beca88e013011f93b04 to your computer and use it in GitHub Desktop.
Save mattifestation/cffeecfcee806beca88e013011f93b04 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