我想使用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
模块?
答案 0 :(得分:1)
可以使用导入PKI模块
Import-Module -Name C:\Windows\System32\WindowsPowerShell\v1.0\Modules\PKI\pki.psd1
在PowerShell v6.0.4上
或
Import-Module -Name C:\Windows\System32\WindowsPowerShell\v1.0\Modules\PKI\pki.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:\LocalMachine\My\494D1D7AFE42DD86D3968814CD4530AF29288BE1 -AllowUntrustedRoot
Test-Certificate : The type initializer for '<Module>' threw an exception.
At line:1 char:1
+ Test-Certificate -Cert Cert:\LocalMachine\My\494D1D7AFE42DD86D396881 ...
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], TypeInitializationException
+ FullyQualifiedErrorId : System.TypeInitializationException
这意味着您当前将无法直接在PowerShell v6.x中使用cmdlet。
您可以做的是创建一个到本地计算机的PowerShell远程处理会话(WinRM),然后将PKI模块导入该会话。这将为您提供可以在PowerShell v6中使用的cmdlet的代理功能。如果要在另一个PowerShell v6会话中使用PKI模块,则必须重复导入