For a while i have had a niggling issue where on a DC that is used by a number of in-house coded applications, WinRM would fail intermittently with the following:
Log : Microsoft-Windows-WinRM/Operational
EventID : 142
Event Message: WSMan operation Enumeration failed, error code 2150859046
There isn’t much to go on for this error when googling – and MS support – well… no point in trying that.
After verifying permissions and configuration, checking server resources etc… i was at a point where i didnt know how to “fix” it or even have any leads.
I initially put in a simply script to restart the service nightly… but every now and again, the stop of the service would hang…. so i’d have to kill the process.
I’ve ended up going down a path of:
- Attaching a scheduled task to eventID 142
- To get around powershell restrictions – have it launch a batch file containing
reg add HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell /v ExecutionPolicy /t REG_SZ /d unrestricted /f
powershell.exe -NoProfile -NoLogo -NonInteractive -ExecutionPolicy Unrestricted -File C:\data\TerminateAndRestartWinRM.ps1
reg add HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell /v ExecutionPolicy /t REG_SZ /d AllSigned /f
TerminateAndRestartWinRM.ps1 contains
Start-Transcript C:\Data\WinRMTerminate.log
write-host “Getting the WinRM ProcessID”
$winRMService = Get-WmiObject -Class Win32_Service -Filter “Name=’WinRM'”
$processId = $winRMService.ProcessId
write-host “Terminating processID: $ProcessId”
Stop-Process -Id $processId -Force
write-host “Sleeping for 10 seconds to wait for process to terminate”
Start-Sleep -seconds 10
write-host “Starting WinRM”
# Start the WinRM service
Start-Service -Name WinRM
Stop-Transcript
Not the best thing ever – and i generally don’t like these types of “hacky” solutions…. but given that MS has moved from “mostly unsupported” to “completely unsupported” for everything that isn’t in Azure…. (which even then is mostly unsupported)… we don’t have much choice anymore.