Translate()
The following
PowerShell scriptles try to demonstrate how an
NTAccount
can be translated (converted) to a
SecurityIdentifier
(
SID), and vice versa.
Translate from Sid to name
$sid = new-object System.Security.Principal.SecurityIdentifier 'S-1-5-18'
$name = $sid.Translate([type]'System.Security.Principal.NTAccount')
$name.GetType().FullName
#
# System.Security.Principal.NTAccount
#
# Show name
#
write-output $name.Value
#
# NT AUTHORITY\SYSTEM
Translate from name to SID
#
# Create a new NTAccount object from a given name
#
$localAdmin = new-object System.Security.Principal.NTAccount 'BUILTIN\Administrators'
#
# Convert (translate) the NTAccount into a SecurityIdentifier object:
#
$sid = $localAdmin.Translate([type]'System.Security.Principal.SecurityIdentifier')
$sid.GetType().FullName
#
# System.Security.Principal.SecurityIdentifier
#
# Show the SID
#
write-output $sid.Value
#
# S-1-5-32-544