From the following block of PS
$myAppDomain = [System.AppDomain]::CurrentDomain
$myPrincipal = [System.Security.Principal.PrincipalPolicy]::WindowsPrincipal
$myAppDomain.SetPrincipalPolicy($myPrincipal)
$myPrincipalPermission = New-Object -TypeName System.Security.Permissions.PrincipalPermission -ArgumentList $null, "Administrators"
$myPrincipalPermission.Demand()
I am getting the following exception.
Exception calling "Demand" with "0" argument(s): "Request for principal permission failed." At line:1 char:30 + $myPrincipalPermission.Demand <<<< () + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException
The version of PowerShell is
$PSVersionTable Name Value ---- ----- CLRVersion 2.0.50727.8762 BuildVersion 6.1.7601.17514 PSVersion 2.0 WSManStackVersion 2.0 PSCompatibleVersions {1.0, 2.0} SerializationVersion 1.1.0.1 PSRemotingProtocolVersion 2.1
I wrote the script based on the PrincipalPermission
class documentation.