Get the user claim token string in powershell from Windows domain/name


To grab the User Claim token equivalent of their Windows Domain/Name in powershell you just need to have the following Get-SPClaim function within your script.

Add-PSSnapin Microsoft.SharePoint.PowerShell
$m = [Microsoft.SharePoint.Administration.Claims.SPClaimProviderManager]::Local

Function Get-SPClaim{
param([string]$user)
$claim = New-SPClaimsPrincipal -identity $user -IdentityType "WindowsSamAccountName"
return $m.EncodeClaim($claim)
}

$UserClaim = Get-SPClaim("cannonfodder\administrator")
Write-Host $UserClaim

The above code will display the following on the screen.

i:0#.w|cannonfodder\administrator

Advertisements