Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to install the PKI module on Powershell Core?

I'd like to use the various commands from Powershell 5's PKI module:

$ 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

However running Install-Module -Name PKI returns

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

There is PSPKI, but PSPKI is a third party module that has a different API and commands:

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

How do I install the PKI module on Powershell Core 6?

like image 940
mikemaccana Avatar asked Aug 31 '18 11:08

mikemaccana


People also ask

How do I install a module in PowerShell?

At the PowerShell prompt, type Get-Module -ListAvailable to see which modules are active. To install a module, use the Get-InstalledModule cmdlet.

What is PKI module?

This module is intended to simplify various PKI and Active Directory Certificate Services management tasks by using automation with Windows PowerShell. The module provides features and capabilities for managing and configuring Certification Authorities.


1 Answers

The PKI module can be imported using

Import-Module -Name C:\Windows\System32\WindowsPowerShell\v1.0\Modules\PKI\pki.psd1

on PowerShell v6.0.4

or

Import-Module -Name C:\Windows\System32\WindowsPowerShell\v1.0\Modules\PKI\pki.psd1 -SkipEditionCheck

on PowerShell v6.1 release candidate 1

BUT the two cmdlets I tested both failed to run

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

Which means that you're not going to be able to use the cmdlets directly in PowerShell v6.x at the moment.

What you could do is create a PowerShell remoting session (WinRM) to the local machine then import the PKI module into that session. That would give you proxy functions for the cmdlets that you could use from PowerShell v6. You'd have to repeat the import if you wanted to use the PKI module in another PowerShell v6 session

like image 97
Richard Siddaway Avatar answered Oct 02 '22 03:10

Richard Siddaway