powershell - 从哪里开始为此创建 Powershell 脚本?

标签 powershell x509certificate

如果我需要向证书授予如下所述的附加权限,我应该在 Powershell 中从哪里开始?必须有一个 Windows 命令行可执行文件,我必须从命令行启动它。只有这样我才能考虑用powershell脚本编写它,对吧?

  1. Click Start, type mmc in the Search programs and files box, and then press ENTER.
  2. On the File menu, click Add/Remove Snap-in.
  3. Under Available snap-ins, double-click Certificates.
  4. Select Computer account, and then click Next.
  5. Click Local computer, and then click Finish. Click OK.
  6. Under Console Root, Certificates (Local Computer), in the Personal store, click Certificates.
  7. Right-click xxAzurehost1 certificate that has been created earlier. Choose All Tasks > Manage Private Keys. Click Add and then Advanced. Click Locations and choose your local computer. Click Find Now. Select NETWORK SERVICE in the search results and click OK. Click OK. In the Permissions for xxxazurehost1 private keys window, select NETWORK SERVICE and give Read permissions. Click OK.

最佳答案

要控制私钥的 ACL,您只需编辑文件 ACL。诀窍是找到哪个文件。

私钥存储在:

%ProgramData%\Microsoft\Crypto

在 XP 上:

C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto

在此处您将看到按算法组织的键,例如DSS、RSA。

用户存储将是带有用户 SID 的子文件夹。本地计算机存储将位于子文件夹中:

MachineKeys

以下是获取存储证书私钥信息的文件的方法。

  1. 首先进入本地机器个人证书存储:

    PS> cd cert:\LocalMachine\My
    
  2. 现在您必须获取您的证书的句柄。执行此操作的方法不止一种,这里是使用指纹的一种方法:

    $cert = dir | ? {$_.Thumbprint -eq "232820EEBF7DBFA01EE68A28BA0450671F862AE1"}
    
  3. 现在您可以找到如下私钥文件名:

    $fileName = $cert.PrivateKey.CspKeyContainerInfo.UniqueKeyContainerName
    $keyFile = dir -Path "C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto" -Recurse | ? {$_.Name -eq $fileName}
    
  4. $keyFile 将是 FileInfo 对象,您可以使用 Set-ACL 或 icacls.exe 更改 ACL

关于powershell - 从哪里开始为此创建 Powershell 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8376468/

相关文章:

windows - 仅在指定的情况下才要求信用

powershell - 检查帐户是否是本地组的成员并在 powershell 2.0 中执行 IF/ELSE

powershell - Azure 自动化、PowerShell 用于获取私有(private) blob 容器中的文件

powershell - 如何使字符串段落更易于阅读源代码

c# - 解码X509Certificate2的序列号?

Ruby 生成自签名证书

.net - 如何在 Windows Azure 上获取代码证书

powershell - 将值传递给PowerShell。退出事件操作

java - 对于非证书输入,CertificateFactory 返回 null

Java http(s) 客户端没有失败