Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

using invoke-command to install certifications unuseable

$
0
0

Hi,Everybody

I want to install some certificates in a domain from a domain controller for RDS. The installation is successful, but when deploying remoteApp programs, the RDS complains the certificate is invalid. But if I install the certificate locally, it works.

What's the difference between invoke-command and local command.

If i run the following script on the domain-controller as a domain administrator,the cert will be invalid.(RDS deploying will complain)

the command is :invoke-command -comp vm135 -filepath c:\powershell\testCert.ps1

If i run it on the domain member locally as a  domain administrator , the cert will be valid.

the command is : powershell c:\powershell\testCert.ps1

the detail code is as follow:

#invoke-command -comp vm135 -filepath c:\powershell\testCert.ps1


[System.Security.Cryptography.X509Certificates.X509KeyStorageFlags] $StorageFlag = [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable 
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 ("C:\subCer.pfx","123456",$StorageFlag); 
$cert1 = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 ("C:\RootCa.cer"); 

  if ($cert)
  {
    $StoreName="My";
$StoreScope = "LocalMachine"
if (Test-Path "cert:\$StoreScope\$StoreName")
{
try
{ 
 $store = New-Object System.Security.Cryptography.X509Certificates.X509Store $StoreName, $StoreScope
 $store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
 $store.Add($cert) 
 $store.Close()
 Write-Host "Successfully added  to 'cert:\$StoreScope\$StoreName'."
 $result = dir  "cert:\$StoreScope\$StoreName";
 "cert: $result";
 $StoreName = "Root";
 $store = New-Object System.Security.Cryptography.X509Certificates.X509Store $StoreName, $StoreScope
 $store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
 $store.Add($cert1) 
 $store.Close()
 Write-Host "Successfully added  to 'cert:\$StoreScope\$StoreName'."
 $result = get-item "cert:\LocalMachine\Root\B3AE574CBE18B1D998C7E2FEECD870CE6A4BC5B9"
 "cert: $result";  
}

catch
{
 Write-Error ("Error adding  to 'cert:\$StoreScope\$StoreName'")
}
}

  }  



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>