Get SID of Active Directory Forest

$rootDomainSid = (Get-ADDomain -Server (Get-ADForest).RootDomain).DomainSID.value

$hasher = [System.Security.Cryptography.HashAlgorithm]::Create('sha256')

$hash = $hasher.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($rootDomainSid))

$hashString = [System.BitConverter]::ToString($hash)

$hashString.Replace('-', '')

Comments