Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install a Certificates using powershell script

I am trying to install a certificate through a PowerShell script. I am using the Import-Certificate method, as suggested in the Microsoft PowerShell documentation.

Here's my code:

$script = {
    $file = ( Get-ChildItem -Path  C:\Users\Administrator\Desktop\newCert.cer )
    $file | Import-Certificate -CertStoreLocation cert:\CurrentUser\Root
    echo $file
    }

invoke-command -Credential $clientCred -ComputerName $ClientIP -ScriptBlock $script

I get the following error:

UI is not allowed in this operation
    + CategoryInfo          : InvalidArgument: (:) [Import-Certificate], ArgumentException 

I'm not sure where is this going wrong - it would be really helpful if someone could point me in the right direction.

like image 562
Shadid Avatar asked Apr 12 '16 18:04

Shadid


People also ask

How do I install certificates?

Import the certificate into the local computer storeIn the Open box, type mmc, and then select OK. On the File menu, select Add/Remove snap-in. In the Add/Remove Snap-in dialog box, select Add. In the Add Standalone Snap-in dialog box, select Certificates, and then select Add.

How do I import certificates to my computer?

Navigate to Personal | Certificates pane. Right-click within the Certificates panel and click All Tasks | Import to start the Certificate Import Wizard. Follow the wizard to import the signed certificate along with the private key.


1 Answers

The problem here is that when you install the certificate to Cert:\CurrentUser\Root (Trusted Root CAs in the current user account), underlying CryptoAPI invokes the following dialog:

enter image description here

And this is why error message mentions UI. Since you are attempting to install the certificate in the remoting session it is impossible to press the button in the remote host's interactive session. This is why UI dialogs are prohibited.

What you can do is to install the certificate to Local Machine store. That is, install it to Cert:\LocalMachine\Root.

Note that when installing a root certificate to the local machine store, it is automatically propagated to all user accounts on that machine. That is, an unintentional trust can be established for users where such trust might not be supposed.

like image 136
Crypt32 Avatar answered Oct 08 '22 20:10

Crypt32