Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Accessing website with certificate authentication from Powershell

$
0
0

I am using powershell script which sends xml message to a web service and to send data it needs to provide certificate for authentication.  I have got this to work if I just have one cert under cert:\LocalUser\My  location but let's say I have multiple certs, how do I choose the correct one to use.  Here is the code I'm using to send XML message

    $parameters = "<message>......</message>"
    $http_request = New-Object -ComObject Msxml2.ServerXMLHTTP.6.0
    $http_request.setOption(2, 13056)
    $http_request.open('POST', $URL, $false)
    $http_request.setRequestHeader("Content-type", "text/xml")
    $http_request.setRequestHeader("Content-length", $parameters.length)
    $http_request.setRequestHeader("Connection", "close")
    $http_request.send($parameters)

The above works because if I have one cert, but it doesn't work if I have multiple cert under cert:\LocalUser\My  location because it has to use the correct cert which is not the case by default.  Is there a way to do this? 

Also another optional question, you can discard if you don't know this answer: How is the best way to sign this script with the same cert or covert this cert to make it code signing cert?

Thanks!!!


sjoshi


Viewing all articles
Browse latest Browse all 15028

Trending Articles



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