Skip to content

Commit 39c63f7

Browse files
committed
Adds WinRM client certificate auth script with self signed cert
1 parent 5c84e68 commit 39c63f7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
$client_cert_pfx = "$(pwd)\winrm_client_cert.pfx"
2+
$client_cert_pfx_password = "Passw0rd"
3+
$remote_host = "192.168.209.147"
4+
5+
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store(
6+
[System.Security.Cryptography.X509Certificates.StoreName]::My,
7+
[System.Security.Cryptography.X509Certificates.StoreLocation]::CurrentUser)
8+
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
9+
10+
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2(
11+
$client_cert_pfx, $client_cert_pfx_password,
12+
([System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::MachineKeySet -bor
13+
[System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::PersistKeySet))
14+
$store.Add($cert)
15+
16+
$opt = New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck
17+
$session = New-PSSession -ComputerName $remote_host -UseSSL -CertificateThumbprint $cert.Thumbprint -SessionOption $opt
18+
Enter-PSSession $session

0 commit comments

Comments
 (0)