Last active
April 30, 2021 19:58
-
-
Save bixb0012/eeb75d64784556df5b7c25da48f44b3d to your computer and use it in GitHub Desktop.
PowerShell: Security-related
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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