Use the Import-Certificate cmdlet in PowerShell to install the certificate to the certificate store. It takes the certificate file and certificate store location to import the certificate to the store.
Using the PowerShell script is an easy and quick way to import the certificate to the store from the .cer file. Another way to install the certificate is to use the mmc snap-in UI wizard.
In this article, we will discuss how to import certificates to the certificate store using the PowerShell Import-Certificate command and install the certificate on the remote computer using the Invoke-Command method.
PowerShell Import Certificate on Local Computer
Use the Import-Certificate cmdlet to install a certificate to the certificate store in Windows OS.
Import-Certificate -FilePath D:\exported_iis.cer -CertStoreLocation Cert:\LocalMachine\My\
In the above PowerShell script, the Import-Certificate command uses the FilePath
parameter to specify the certificate file location on the Windows OS drive and the CertStoreLocation
parameter to specify the certificate store path.
It imports the certificate to the Cert:\LocalMachine\My\
store location path and displays the certificate thumbprint and subject details as given below.
PowerShell Install Certificate on Remote Computer
Use the Import-Certificate command in combination with the Invoke-Command
method to import a certificate on the remote computer.
The Invoke-Command method takes the remote computer name and uses the ScriptBlock
to run the Import-Certificate script to import the certificate to the store.
Invoke-Command -ComputerName CORP-EU-101 -ScriptBlock {Import-Certificate -FilePath D:\exported_iis.cer -CertStoreLocation Cert:\LocalMachine\My\ }
The output of the above PowerShell script will successfully import the certificate on the remote computer and display the certificate thumbprint and subject details.
Conclusion
I hope the above article on how to import the certificate on local and remote computers using the Import-Certificate command is helpful to you.
You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.
Recommended Article
How to create a self-signed certificate in PowerShell
How to bind a certificate to the IIS site
How to delete a self-signed certificate on the Windows operating system
How to export certificate from the certificate store using PowerShell