I have this setup, I have a HostPC which will connect with say two remote PCs in order to run PowerShell commands. So, I will be using WSManConnectionInfo for this with HTTPS. I am just stuck around concept of using Kerberos and Certificate in terms of authenticating connection.
Here are the questions:
- From what I understand from WSMan is that WSManConnectionInfo will be using both Kerberos and Negotiate as methods of authentication by default to verify the connection is done on a domain or through localhost. Am I right?
- If I am using Certificate authentication, how can I setup the WinRM on HostPC and remote PCs using certificates from code below in PowerShell Script
New-SelfSignedCertificate `
-DnsName <PCName> `
-CertStoreLocation <Path> `
-KeyLength 2048 `
-NotAfter (Get-Date).AddYears(xx) `
-TextExtension @("2.5.29.37={text}<OID Purpose>")
The way I approached this by using the video tutorial below,
Configure WinRM over HTTPS with Self signed Certificate
So when I used the WinRM for setting up the Listener, I used the remote PCs certificates to be used in the Listener
winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname="<RemotePCName>";CertificateThumbprint="<RemotePC Certificate Thumbprint>"}'
Then in the HostPC I just used
connectionInfo = new WSManConnectionInfo(new Uri($"https://{MachineName}:5986/wsman"),"http://schemas.microsoft.com/powershell/Microsoft.PowerShell", new PSCredential(<username>,<password>);
and it worked fine with no issues, but, I have a feeling it should be done like this. What have I done wrong and also can you please advice on the part about the certificate creation, import and export as I am confused at how it should be done.
I know that in the WSManConncetion I can use
connectionInfo.CertificateThumbprint = <Certificate Thumbprint>