Enable WinRM Remotely

# Set variables
$server="SHERVER007"

# Enable WinRM Remotely
psexec.exe \\$remoteHost -s C:\Windows\system32\winrm.cmd qc -quiet
# Invoke-WmiMethod -ComputerName $server -Class Win32_Process -Name Create -ArgumentList "C:\Windows\system32\winrm.cmd -q"

# Test to see if WinRM is indeed installed
test-netconnection $remoteHost -port 5985

# Enter PowerShell session on remote host
enter-pssession $remotehost

Scripty

function pingTest{
Param([string]$node)
try{
Return Test-Connection $node -Count 1 -Quiet -ea Stop;
}
catch{Return $False}
}

function enableRemoteWinRM{
Param([string]$computername)
if (pingTest $computername){
try{
$isWinRMEnabled = Test-WSMan $computername -ea Stop
}
catch{
$isWinRMEnabled=$False
Write-Host "WinRM has not been detected. Enabling now..."
continue;
}
if (!($isWinRMEnabled)){psexec.exe \\$computername -s C:\Windows\system32\winrm.cmd qc -quiet}
else{Write-Host "WinRM has been already enabled. No changes to WinRM have been made."}
}
Else{Write-Host "Unable to determine if WinRM is enabled on $computername`.`n Ping test has failed. Check if this computer is online and whether there's a firewall blocking of ICMP";}
}

enableRemoteWinRM;

Leave a Reply

Your email address will not be published. Required fields are marked *