方法调用失败,因为[System.Management.Automation.PSMethod]不包含名为“AddAccessRule”的方法

时间:2016-10-07 07:15:27

标签: powershell

我正在尝试通过PowerShell授予私钥证书。执行行$acl.AddAccessRule($accessRule)时显示错误。有人可以帮我这个。错误是方法调用失败,因为[System.Management.Automation.PSMethod]不包含名为“AddAccessRule”的方法。

$pfxThumbPrint = "4de676d05fd9b10d6a4d2d8b9305c004735800bc3"
    $cert = Get-ChildItem -Path cert:\LocalMachine\Root | Where-Object -FilterScript { $PSItem.ThumbPrint -eq $pfxThumbPrint; };

$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("NETWORK SERVICE","Read,FullControl","Allow")

$keyPath = $env:ProgramData + "\Microsoft\Crypto\RSA\MachineKeys\";
$keyName = $cert.PrivateKey.CspKeyContainerInfo.UniqueKeyContainerName;
$keyFullPath = $keyPath + $keyName;

$keyFullPath

# Get the current acl of the private key
$acl = (Get-Item $keyFullPath).GetAccessControl

# Add the new ace to the acl of the private key
$acl.AddAccessRule($accessRule);

# Write back the new acl
Set-Acl -Path $keyFullPath -AclObject $acl;

0 个答案:

没有答案