Skip to content

Instantly share code, notes, and snippets.

@diecknet
Forked from IISResetMe/Get-MachineSID.ps1
Last active April 21, 2023 07:49
Show Gist options
  • Save diecknet/139e73a5ab027f38870bc20ffa9e4744 to your computer and use it in GitHub Desktop.
Save diecknet/139e73a5ab027f38870bc20ffa9e4744 to your computer and use it in GitHub Desktop.
PsGetSid local machine SID implementation in PowerShell
function Get-MachineSID {
# Going for the local SID by finding a local account and removing its Relative ID (RID)
$LocalAccountSID = Get-WmiObject -Query "SELECT SID FROM Win32_UserAccount WHERE LocalAccount = 'True'" |Select-Object -First 1 -ExpandProperty SID
$MachineSID = $LocalAccountSID -replace '-[^-]+$'
return $MachineSID
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment