1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# // first argument is mapped to $url param($url) [Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} [System.Uri] $u = New-Object System.Uri($url) [Net.ServicePoint] $sp = [Net.ServicePointManager]::FindServicePoint($u); [System.Guid] $groupName = [System.Guid]::NewGuid() # // create a request [Net.HttpWebRequest] $req = [Net.WebRequest]::create($url) $req.Method = "GET" $req.Timeout = 600000 # = 10 minutes $req.ConnectionGroupName = $groupName # // Set if you need a username/password to access the resource #$req.Credentials = New-Object Net.NetworkCredential("username", "password"); [Net.HttpWebResponse] $result = $req.GetResponse() $sp.CloseConnectionGroup($groupName) $fullPathIncFileName = $MyInvocation.MyCommand.Definition $currentScriptName = $MyInvocation.MyCommand.Name $currentExecutingPath = $fullPathIncFileName.Replace($currentScriptName, "") $outfilename = $currentExecutingPath + "Export.cer" [System.Byte[]] $data = $sp.Certificate.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Cert) [System.IO.File]::WriteAllBytes($outfilename, $data) Write-Host $outfilename Import-Certificate -FilePath $outfilename -CertStoreLocation 'Cert:\LocalMachine\Root' -Verbose #CertUtil -addStore Root $outfilename |