Disable-WinRM.ps1
Function Disable-WinRM { if ([bool](Get-Service -Name "WinRM" | Where-Object {$_.Status -eq "Running"})){ Remove-Item -Path WSMan:\Localhost\listener\listener* -Recurse -ErrorAction SilentlyContinue (Disable-PSRemoting) | Out-Null Set-NetFirewallRule -DisplayName 'Windows Remote Management (HTTP-In)' -Enabled False -PassThru | Select -Property DisplayName, Profile, Enabled Stop-Service "WinRM" -ErrorAction SilentlyContinue -Force return "WinRM Disbled" } elseif ([bool](Get-Service -Name "WinRM" | Where-Object {$_.Status -eq "Stopped"})) {return "Service Already Disabled"} } |