2016 – PnP: add a claim value to an SP group using PnP powershell

I was hoping to find an example where I could add a particular custom claim value to an SP group using PnP Powershell.

Basically, do what you do next using PnP powershell

$ ClaimValue = $.ClaimValue
yes ($
.ClaimType -eq $ ClaimTypeSchema.GroupSID)
{
$ objUserAccount = New-Object System.Security.Principal.NTAccount ($ EnvUserDomain, $.ClaimValue)
$ objUserSID = $ null
Write-Output ("Generation of security identifier for the account: & # 39;" + $
.ClaimValue + "& # 39; …")
$ objUserSID = $ objUserAccount.Translate ([System.Security.Principal.SecurityIdentifier])
if ($ objUserSID -eq $ null)
{
continue
}
$ ClaimValue = $ objUserSID.Value
}
Write-Output ("Add claim: & # 39;" + $.ClaimType + "& # 39; with Value: & # 39;" + $ ClaimValue + "& # 39; …")
$ Claim = New-SPClaimsPrincipal -ClaimType $
.ClaimType -ClaimValue $ ClaimValue -TrustedIdentityTokenIssuer $ AuthenticationProvider
$ SPUserClaim = New-SPUser -UserAlias ​​$ Claim.ToEncodedString () -Web $ RootWeb.Url
$ SecurityGroup.AddUser ($ SPUserClaim)
}
Write-out "Completed"