是否可以在Powershell Core上安装PKI模块?



我想使用Powershell 5的PKI模块中的各种命令:

$ Get-Command -module PKI
CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Add-CertificateEnrollmentPolicyServer              1.0.0.0    PKI
Cmdlet          Export-Certificate                                 1.0.0.0    PKI
Cmdlet          Export-PfxCertificate                              1.0.0.0    PKI
Cmdlet          Get-Certificate                                    1.0.0.0    PKI
Cmdlet          Get-CertificateAutoEnrollmentPolicy                1.0.0.0    PKI
Cmdlet          Get-CertificateEnrollmentPolicyServer              1.0.0.0    PKI
Cmdlet          Get-CertificateNotificationTask                    1.0.0.0    PKI
Cmdlet          Get-PfxData                                        1.0.0.0    PKI
Cmdlet          Import-Certificate                                 1.0.0.0    PKI
Cmdlet          Import-PfxCertificate                              1.0.0.0    PKI
Cmdlet          New-CertificateNotificationTask                    1.0.0.0    PKI
Cmdlet          New-SelfSignedCertificate                          1.0.0.0    PKI
Cmdlet          Remove-CertificateEnrollmentPolicyServer           1.0.0.0    PKI
Cmdlet          Remove-CertificateNotificationTask                 1.0.0.0    PKI
Cmdlet          Set-CertificateAutoEnrollmentPolicy                1.0.0.0    PKI
Cmdlet          Switch-Certificate                                 1.0.0.0    PKI
Cmdlet          Test-Certificate                                   1.0.0.0    PKI

但是,运行Install-Module -Name PKI返回

No match was found for the specified search criteria and module name 'PKI'

PSPKI,但PSPKI是一个第三方模块,具有不同的API和命令:

Get-Command -Module PSPKI
CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           Add-AIA                                            3.3.0.0    PSPKI
Alias           Add-CAACL                                          3.3.0.0    PSPKI
Alias           Add-CDP                                            3.3.0.0    PSPKI
Alias           Connect-CA                                         3.3.0.0    PSPKI
Alias           Disable-CRLFlag                                    3.3.0.0    PSPKI
Alias           Disable-KRAFlag                                    3.3.0.0    PSPKI
Alias           Enable-CRLFlag                                     3.3.0.0    PSPKI
Alias           Enable-KRAFlag                                     3.3.0.0    PSPKI
Alias           Get-AIA                                            3.3.0.0    PSPKI
Alias           Get-CA                                             3.3.0.0    PSPKI
Alias           Get-CAACL                                          3.3.0.0    PSPKI
Alias           Get-CDP                                            3.3.0.0    PSPKI
Alias           Get-CRL                                            3.3.0.0    PSPKI
Alias           Get-CRLFlag                                        3.3.0.0    PSPKI
Alias           Get-CTL                                            3.3.0.0    PSPKI
Alias           Get-KRAFlag                                        3.3.0.0    PSPKI
Alias           Remove-AIA                                         3.3.0.0    PSPKI
Alias           Remove-CAACL                                       3.3.0.0    PSPKI
Alias           Remove-CDP                                         3.3.0.0    PSPKI
Alias           Remove-Request                                     3.3.0.0    PSPKI
Alias           Restore-CRLFlagDefault                             3.3.0.0    PSPKI
Alias           Restore-KRAFlagDefault                             3.3.0.0    PSPKI
Alias           Set-CAACL                                          3.3.0.0    PSPKI
Alias           Set-CDP                                            3.3.0.0    PSPKI
Alias           Show-CRL                                           3.3.0.0    PSPKI
Alias           Show-CTL                                           3.3.0.0    PSPKI
Function        Convert-PemToPfx                                   3.3.0.0    PSPKI
Function        Convert-PfxToPem                                   3.3.0.0    PSPKI
Function        Get-CertificateContextProperty                     3.3.0.0    PSPKI
Function        Get-CertificateRequest                             3.3.0.0    PSPKI
Function        Get-CertificateRevocationList                      3.3.0.0    PSPKI
Function        Get-CertificateTrustList                           3.3.0.0    PSPKI
Function        Get-CryptographicServiceProvider                   3.3.0.0    PSPKI
Function        Get-EnrollmentPolicyServerClient                   3.3.0.0    PSPKI
Function        Get-ErrorMessage                                   3.3.0.0    PSPKI
Function        Get-ObjectIdentifier                               3.3.0.0    PSPKI
Function        Get-ObjectIdentifierEx                             3.3.0.0    PSPKI
Function        New-SelfSignedCertificateEx                        3.3.0.0    PSPKI
Function        Ping-ICertInterface                                3.3.0.0    PSPKI
Function        Receive-Certificate                                3.3.0.0    PSPKI
Function        Register-ObjectIdentifier                          3.3.0.0    PSPKI
Function        Show-Certificate                                   3.3.0.0    PSPKI
Function        Show-CertificateRevocationList                     3.3.0.0    PSPKI
Function        Show-CertificateTrustList                          3.3.0.0    PSPKI
Function        Start-PsFCIV                                       3.3.0.0    PSPKI
Function        Submit-CertificateRequest                          3.3.0.0    PSPKI
Function        Test-WebServerSSL                                  3.3.0.0    PSPKI
Function        Unregister-ObjectIdentifier                        3.3.0.0    PSPKI

如何在Powershell Core 6上安装PKI模块?

可以使用

Import-Module -Name C:WindowsSystem32WindowsPowerShellv1.0ModulesPKIpki.psd1

在PowerShell v6.0.4上

Import-Module -Name C:WindowsSystem32WindowsPowerShellv1.0ModulesPKIpki.psd1 -SkipEditionCheck

在 PowerShell v6.1 候选版本 1 上

但是我测试的两个 cmdlet 都无法运行

PS>  Get-Certificate
Get-Certificate : The type initializer for '<Module>' threw an exception.
At line:1 char:1
+ Get-Certificate
+ ~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], TypeInitializationException
+ FullyQualifiedErrorId : System.TypeInitializationException
PS>  Test-Certificate -Cert  Cert:LocalMachineMy494D1D7AFE42DD86D3968814CD4530AF29288BE1 -AllowUntrustedRoot
Test-Certificate : The type initializer for '<Module>' threw an exception.
At line:1 char:1
+ Test-Certificate -Cert  Cert:LocalMachineMy494D1D7AFE42DD86D396881 ...
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], TypeInitializationException
+ FullyQualifiedErrorId : System.TypeInitializationException

这意味着你目前无法直接在PowerShell v6.x中使用cmdlet。

您可以做的是创建到本地计算机的 PowerShell 远程处理会话 (WinRM(,然后将 PKI 模块导入该会话。这将为你提供可从 PowerShell v6 使用的 cmdlet 的代理函数。 如果要在另一个 PowerShell v6 会话中使用 PKI 模块,则必须重复导入

相关内容

  • 没有找到相关文章

最新更新