File tree 1 file changed +27
-0
lines changed
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ $ErrorActionPreference = " Stop"
2
+
3
+ $username = " Administrator"
4
+ $password = " Passw0rd"
5
+
6
+ $client_cert_path = " $ ( pwd) \cert.pem"
7
+
8
+ # Enable certificate authentication
9
+ & winrm set winrm/ config/ service/ auth ` @` {Certificate= `" true`" ` }
10
+
11
+ # Import the client cert as a CA cert
12
+ $clientcert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($client_cert_path )
13
+ $castore = New-Object System.Security.Cryptography.X509Certificates.X509Store(
14
+ [System.Security.Cryptography.X509Certificates.StoreName ]::Root,
15
+ [System.Security.Cryptography.X509Certificates.StoreLocation ]::LocalMachine)
16
+ $castore.Open ([System.Security.Cryptography.X509Certificates.OpenFlags ]::ReadWrite)
17
+ $castore.Add ($clientcert )
18
+
19
+ $secure_password = ConvertTo-SecureString $password - AsPlainText - Force
20
+ # For domain auth just replace $ENV:COMPUTERNAME with the domain name
21
+ $cred = New-Object System.Management.Automation.PSCredential " $ENV: COMPUTERNAME \$username " , $secure_password
22
+
23
+ # Get the UPN from the cert extension
24
+ $clientcert.Extensions [1 ].Format($false ) -match " .*=(.*)"
25
+ $upn = $Matches [1 ]
26
+
27
+ New-Item - Path WSMan:\localhost\ClientCertificate - Issuer $clientcert.Thumbprint - Subject $upn - Uri * - Credential $cred - Force
You can’t perform that action at this time.
0 commit comments