Skip to content

Instantly share code, notes, and snippets.

@bixb0012
Last active April 30, 2021 19:58
Show Gist options
  • Save bixb0012/eeb75d64784556df5b7c25da48f44b3d to your computer and use it in GitHub Desktop.
Save bixb0012/eeb75d64784556df5b7c25da48f44b3d to your computer and use it in GitHub Desktop.
PowerShell: Security-related
#Requires -Version 5.1
# Reference: 1) https://docs.microsoft.com/en-us/dotnet/api/system.security.principal
# Example 1: Retrieve security identifier value (SID) for an NT account
# Adapted from https://devblogs.microsoft.com/scripting/use-powershell-to-translate-a-users-sid-to-an-active-directory-account-name/
$DomainName = "" # Domain of account, commonly $Env:USERDOMAIN
$AccountName = "" # Name of account, commonly $Env:USERNAME
$NTAccount = [Security.Principal.NTAccount]::New($DomainName, $AccountName)
$Sid = ($NTAccount.Translate([Security.Principal.SecurityIdentifier])).Value
# Example 2: Retrieve account domain and name for a security identifier (SID) value
$Sid = "" # String representation of security identifier (SID) value
$SecurityIdentifier = [Security.Principal.SecurityIdentifier]::New($Sid)
$NTAccount = $SecurityIdentifier.Translate([Security.Principal.NTAccount])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment