2014-02-20 23 views
3

我试图写一个PowerShell脚本的证书安装到Active Directory证书存储区,PowerShell脚本安装证书到Active Directory商店

下面是步骤手动做到这一点,任何帮助将不胜赞赏。

在Windows 2008 R2域控制器,

点击开始 - >运行

型MMC

单击确定

点击文件 - >添加/删除管理单元

选择 “证书” - >添加

选择“服务帐户”

单击下一步

选择 “本地计算机”

单击下一步

选择 “Active Directory域服务”

单击Finish

点击Ok

我想要脚本t Ø将证书安装到:

NTDS \个人

我会张贴图片,但我没有足够的“名声”很明显,所以我只能提供文字说明。

所以基本上我已经试过是,我用低于这个PowerShell的功能,将证书导入到本地计算机 - >个人商店,这是大多数证书去,和代码工作。

但我需要将证书安装到域控制器上的“NTDS \个人”存储,但$ certRootStore只接受LOCALMACHINE或CurrentUser,所以我坚持:/

function Import-PfxCertificate 
{ 
    param 
    (
     [String]$certPath, 
     [String]$certRootStore = "localmachine", 
     [String]$certStore = "My", 
     $pfxPass = $null 
    ) 
    $pfx = new-object System.Security.Cryptography.X509Certificates.X509Certificate2 

    if ($pfxPass -eq $null) 
    { 
     $pfxPass = read-host "Password" -assecurestring 
    } 

    $pfx.import($certPath,$pfxPass,"Exportable,PersistKeySet") 

    $store = new-object System.Security.Cryptography.X509Certificates.X509Store($certStore,$certRootStore) 
    $store.open("MaxAllowed") 
    $store.add($pfx) 
    $store.close() 
} 

Import-PfxCertificate -certPath "d:\Certificate.pfx" 

问候亚历克斯

+2

,但如果你看看StoreLocation MSDN上只允许CurrentUser和LOCALMACHINE,没有使用“服务帐户”,其中: [StoreLocation枚举(http://msdn.microsoft.com/en- us/library/system.security.cryptography.x509certificates.storelocation(v = vs.110).aspx) –

+0

对不起格式化,不知道如何为PowerShell脚本做语法高亮或代码块。 –

+1

您可以随时编辑您的问题以包含代码和[带有降价格式](http://stackoverflow.com/help/formatting)。然后你可以删除评论。 – jscott

回答

1

好吧,先坏消息。唯一管理证书存储是LocalMachineCurrentUser,因为我们都在PowerShell中看到。

现在,没有那么坏消息。我们知道的“物理”位置存储(物理是MS”字,不是我)在注册表中存在的ADDS服务器,HKLM \ SOFTWARE \微软\加密\ SERVICES \ NTDS \ SystemCertificates上。这是双重双方

  1. 使用procmon同时使用MMC管理单元

  2. 清除MSDN为this nugget

链接在#2所示导入证书进店验证所有服务实体商店都存储在上述路径中,替代NTDS。 真实服务名称,不是显示名称。

然而,

enter image description here

因为坏消息的。试图将它映射到PowerShell中作为根和-PSProvider Certificate将证明令人失望,这是我第一次尝试。

什么人可以尝试,正在使用XMP9Store构造函数,它将IntPtr带到SystemStore,as described here。是的,这invovles一些非托管代码,混合两者是我很少,但this和谷歌搜索HCERTSTORE C#应该让你那里。