GetSidAsBase64

Applies To: Forefront Identity Manager 2010

This is an example of a Windows PowerShell function that converts a system identifier (specified by a domain and account name) into a base-64 string. For more information, see FIM Windows PowerShell Cmdlet Examples.

GetSidAsBase64 Function

The following example function converts a system identifier (specified by a domain and account name) into a base-64 string by using the NTAccount class and the Convert class.

function GetSidAsBase64
{
    PARAM($AccountName, $Domain)
    END
    {   # The following sid is a random value to allocate the byte array
        $sidArray = [System.Convert]::FromBase64String("AQUAAAAAAAUVAAAA71I1JzEyxT2s9UYraQQAAA==") 
        $args = (,$Domain)
        $args += $AccountName
        $ntaccount = New-Object -TypeName System.Security.Principal.NTAccount -ArgumentList $args
        $desiredSid = $ntaccount.Translate([System.Security.Principal.SecurityIdentifier])
        $desiredSid.GetBinaryForm($sidArray,0)
        $desiredSidString = [System.Convert]::ToBase64String($sidArray)
        $desiredSidString
    }
}

See Also

Reference

NTAccount
Convert

Concepts

FIM Windows PowerShell Cmdlet Examples