0% found this document useful (0 votes)
8 views1 page

Secure WinRM Setup Guide for Windows

This document provides a PowerShell script for managing a remote Windows machine using WinRM over HTTPS. It includes steps for importing a certificate, configuring client settings, and establishing both interactive and non-interactive sessions with the remote machine. Additionally, it includes commands for testing the WinRM connection and TCP port accessibility.

Uploaded by

galapek890
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Secure WinRM Setup Guide for Windows

This document provides a PowerShell script for managing a remote Windows machine using WinRM over HTTPS. It includes steps for importing a certificate, configuring client settings, and establishing both interactive and non-interactive sessions with the remote machine. Additionally, it includes commands for testing the WinRM connection and TCP port accessibility.

Uploaded by

galapek890
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

$cerPath = "C:\Temp\winrm_target_192.168.0.242.

cer" # path where you placed the


file
Import-Certificate -FilePath $cerPath -CertStoreLocation Cert:\LocalMachine\Root

Get-ChildItem Cert:\LocalMachine\Root | Where-Object {$_.Subject -like


"*$env:COMPUTERNAME*"} # or search by thumbprint/subject

# ensure AllowUnencrypted is false


Set-Item -Path WSMan:\localhost\Client\AllowUnencrypted -Value $false

# ensure Basic auth allowed on client if you want to send Basic (we'll pass
credentials via Get-Credential)
Set-Item -Path WSMan:\localhost\Client\Auth\Basic -Value $true

Test-WsMan -ComputerName [Link] -UseSSL

$cred = Get-Credential # enter: [Link]\Administrator (or target\user) and


password

# Interactive session
Enter-PSSession -ComputerName [Link] -Credential $cred -UseSSL

# Single command (non-interactive)


Invoke-Command -ComputerName [Link] -Credential $cred -UseSSL -ScriptBlock {
hostname; whoami }

# Test WinRM over HTTPS


Test-WsMan -ComputerName [Link] -UseSSL

# Test TCP port


Test-NetConnection -ComputerName [Link] -Port 5986

$cred = Get-Credential
# When prompted enter: [Link]\Administrator (or target\user) and the
password

# Normal secure connect (trusted cert)


Enter-PSSession -ComputerName [Link] -Credential $cred -UseSSL

# Exit interactive session


Exit-PSSession

You might also like