创建证书的New-SelfSignedCertificate提供了拒绝访问

wil*_*ast 5 windows powershell certificate

我正在尝试New-SelfSignedCertificate在PowerShell中使用Windows 10创建证书,但是该命令给了我权限错误。我正在使用管理员帐户。

命令:

New-SelfSignedCertificate -Type Custom -Subject "CN=Contoso Software, O=Contoso Corporation, C=US" -KeyUsage DigitalSignature -FriendlyName MyCert -CertStoreLocation "Cert:\LocalMachine\My"
Run Code Online (Sandbox Code Playgroud)

输出:

New-SelfSignedCertificate : CertEnroll::CX509Enrollment::_CreateRequest: Access denied. 0x80090010 (-2146893808 NTE_PERM)
At line:1 char:1
+ New-SelfSignedCertificate -Type Custom -Subject "CN=Contoso Software, ..."
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-SelfSignedCertificate], Exception
    + FullyQualifiedErrorId : System.Exception,Microsoft.CertificateServices.Commands.NewSelfSignedCertificateCommand
Run Code Online (Sandbox Code Playgroud)

Bou*_*uke 8

通过指定不同的证书位置为您的本地用户帐户创建证书:

New-SelfSignedCertificate -CertStoreLocation "Cert:\CurrentUser\My" [...]
Run Code Online (Sandbox Code Playgroud)


Ben*_*enH 7

如评论中所述,尽管PowerShell.exe是在具有“管理权限”的用户帐户下运行的。除非提升权限,否则该进程无法使用这些权利。

默认情况下,PowerShell窗口将在标题栏中添加“ Administrator:”。否则,您可以通过运行以下命令来检查您是否是管理员:

([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole??([Security.Principal??.WindowsBuiltInRole] "Administrator")
Run Code Online (Sandbox Code Playgroud)

如果通过GUI完成启动PowerShell的操作,则可以右键单击->以管理员身份运行。

否则,您可以生成一个新的进程,该进程可以通过运行来提升 Start-Process powershell.exe -Verb Runas