SID/User v PowerShell

Predchadzajuci post mi pripomenul, ze existuje jednoducha moznost si tieto prevody robit priamo v PowerShelly. Pre istou dobou som s Mowom (PowerShell MVP) riesil problem, ze najlepsie na skriptovanie je pouzivat priamo SIDy a ze by teda bolo dobre urobit nejake funkcie, ktore by to prevadzali:

function ConvertTo-NtAccount ($sid) {(new-object system.security.principal.securityidentifier($sid)).translate([system.security.principal.ntaccount])}

function ConvertTo-Sid ($NtAccount) {(new-object system.security.principal.NtAccount($NTaccount)).translate([system.security.principal.securityidentifier])}

Ked si pridate tieto funkcie, pracuje sa s nimi naozaj jednoducho.
mzugec>convertto-sid Administrators | format-list

BinaryLength     : 16
AccountDomainSid :
Value            : S-1-5-32-544

mzugec>convertto-sid Administrators | gm

   TypeName: System.Security.Principal.SecurityIdentifier
Name                 MemberType Definition
----                 ---------- ----------
CompareTo            Method     System.Int32 CompareTo(SecurityIdentifier sid)
Equals               Method     System.Boolean Equals(Object o), System.Bool...
GetBinaryForm        Method     System.Void GetBinaryForm(Byte[] binaryForm,...
GetHashCode          Method     System.Int32 GetHashCode()
GetType              Method     System.Type GetType()
get_AccountDomainSid Method     System.Security.Principal.SecurityIdentifier...
get_BinaryLength     Method     System.Int32 get_BinaryLength()
get_Value            Method     System.String get_Value()
IsAccountSid         Method     System.Boolean IsAccountSid()
IsEqualDomainSid     Method     System.Boolean IsEqualDomainSid(SecurityIden...
IsValidTargetType    Method     System.Boolean IsValidTargetType(Type target...
IsWellKnown          Method     System.Boolean IsWellKnown(WellKnownSidType ...
ToString             Method     System.String ToString()
Translate            Method     System.Security.Principal.IdentityReference ...
AccountDomainSid     Property   System.Security.Principal.SecurityIdentifier...
BinaryLength         Property   System.Int32 BinaryLength {get;}
Value                Property   System.String Value {get;}

Martin Zugec

Zdroj: https://thepowershellguy.com