Advertisement
johndoe8

Get-SID

Mar 7th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Get-SID
  2. {
  3.   [CmdletBinding()]
  4.   param
  5.   (
  6.     [Parameter(Mandatory=$true, Position=0)]
  7.     [System.Object]$user
  8.   )
  9.   Try {
  10.     $domain = $env:USERDOMAIN
  11.     $objUser = New-Object System.Security.Principal.NTAccount("$domain","$user") -ErrorAction Stop
  12.     $strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])
  13.     $strSID.Value
  14.     Write-Host
  15.   }
  16.   Catch {
  17.     Write-Error -Message 'Failed to get user SID.'
  18.   }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement