{"id":72941,"date":"2015-10-05T00:01:00","date_gmt":"2015-10-05T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2015\/10\/05\/troubleshoot-winrm-with-powershellpart-1\/"},"modified":"2019-02-18T09:35:00","modified_gmt":"2019-02-18T16:35:00","slug":"troubleshoot-winrm-with-powershellpart-1","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/troubleshoot-winrm-with-powershellpart-1\/","title":{"rendered":"Troubleshoot WinRM with PowerShell&#8212;Part 1"},"content":{"rendered":"<p><b style=\"font-size:12px\">Summary<\/b><span style=\"font-size:12px\">: Ed Wilson, Microsoft Scripting Guy, talks about using Windows PowerShell to look at WinRM logs.<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\" \/>&nbsp;Hey, Scripting Guy! I am having problems with WinRM. When I use the <b>Get-CimInstance<\/b> cmdlet, it fails. When I specify the <b>&ndash;DCOM<\/b> protocol for <b>Get-CimInstance<\/b>, it works. I suspect I have a WinRM problem. How can I go about troubleshooting it?<\/p>\n<p>&mdash;TB<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\" \/>&nbsp;Hello TB,<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. One of the great things about Windows, regardless of the version, is that there are some awesome diagnostics and operational logs. I am not talking about the traditional event logs that have been around since the earliest versions of WinNT (System, Application, and Security logs)&mdash;rather, I am talking about the hundreds of other logs that exist.<\/p>\n<p>Of course, I can open the Event Viewer and go to Microsoft &nbsp;&gt; Windows &gt; Windows Remote Management, then find the Operational log:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-10-5-15-01.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-10-5-15-01.png\" alt=\"Image of menu\" title=\"Image of menu\" \/><\/a><\/p>\n<p>But that is a lot of mousing around. So I can use the <b>Get-WinEvent<\/b> cmdlet, the <b>&ndash;ListLog<\/b> parameter, and a wildcard character to see all of the logs that exist:<\/p>\n<p style=\"margin-left:30px\">Get-WinEvent -ListLog *<\/p>\n<p>When I get through that list, I can look for the log. There is a major issue here, however. First of all, Microsoft-Windows-Windows kind of looks like an error, but, it is really there. Then the Remote Management\/Operational part does not appear to exist. The good thing is that I can use wildcard characters and avoid a lot of typing. Here is the command I use:<\/p>\n<p style=\"margin-left:30px\">Get-WinEvent -ListLog *windows-windows*<\/p>\n<p>The command and its associated output are shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-10-5-15-02.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-10-5-15-02.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>Nope. There is no Windows-Remote-Management anywhere to be found. Dude!<\/p>\n<p>So, I am reduced to piping my log output to <b>More<\/b>, and paging through, one page at a time. Can you say time consuming, frustrating, and total waste of time? Try it. I bet you can.<\/p>\n<p style=\"margin-left:30px\">Get-WinEvent -ListLog * | more<\/p>\n<p>Finally, I find that (for whatever reason), they decided to rename the log name from the display name. I bet that was done to save time.<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; Get-WinEvent -ListLog *winrm*<\/p>\n<p style=\"margin-left:30px\">LogMode&nbsp;&nbsp; MaximumSizeInBytes RecordCount LogName<\/p>\n<p style=\"margin-left:30px\">&#8212;&#8212;- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &nbsp; &nbsp; &nbsp; &#8212;&#8212;&#8212;&#8211; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#8212;&#8212;-<\/p>\n<p style=\"margin-left:30px\">Circular&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1052672&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 16 Microsoft-Windows-WinRM\/Operational<\/p>\n<h2>Clear the operational log<\/h2>\n<p>Windows PowerShell has a <b>Clear-EventLog<\/b> cmdlet, but that only works with traditional logs. To work with the hundreds of other event logs, I need to use the Wevtutil.exe program. Luckily, I can call this command-line tool inside Windows PowerShell, and even pipe stuff to it.<\/p>\n<p>The first thing I like to do when I am troubleshooting is dump the log, and then take steps to re-create the problem. Here is the command to dump the WinRM log:<\/p>\n<p style=\"margin-left:30px\">Get-WinEvent -ListLog *winrm* | % {wevtutil.exe cl $_.LogName}<\/p>\n<p>Now I go back and check to ensure that the log is in fact dumped. These commands and the associated output are shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-10-5-15-03.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-10-5-15-03.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>I want to enable the WinRM log. To do this, again I use the Wevtutil.exe command. But because the command prompts, I need to feed it a <b>Y<\/b> (for yes). I can feed a <b>Y<\/b> to the command by using the echo command. The command to enable the log is shown here:<\/p>\n<p style=\"margin-left:30px\">Get-WinEvent -ListLog *winrm* | % {echo y | wevtutil.exe sl $_.LogName \/e:true}<\/p>\n<p>To double-check that the log is enabled, I pipe the output from <b>Get-WinEvent<\/b> to <b>Format-List<\/b>:<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; Get-WinEvent -ListLog *winrm*&nbsp; | fl *<\/p>\n<p style=\"margin-left:30px\">FileSize&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 69632<\/p>\n<p style=\"margin-left:30px\">IsLogFull&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : False<\/p>\n<p style=\"margin-left:30px\">LastAccessTime&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 8\/6\/2015 4:23:05 PM<\/p>\n<p style=\"margin-left:30px\">LastWriteTime&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 9\/30\/2015 4:46:32 PM<\/p>\n<p style=\"margin-left:30px\">OldestRecordNumber&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 0<\/p>\n<p style=\"margin-left:30px\">RecordCount&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 0<\/p>\n<p style=\"margin-left:30px\">LogName&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: Microsoft-Windows-WinRM\/Operational<\/p>\n<p style=\"margin-left:30px\">LogType&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Operational<\/p>\n<p style=\"margin-left:30px\">LogIsolation&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Application<\/p>\n<p style=\"margin-left:30px\">IsEnabled&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : True<\/p>\n<p style=\"margin-left:30px\">IsClassicLog&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : False<\/p>\n<p style=\"margin-left:30px\">SecurityDescriptor&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;: O:BAG:SYD:(A;;0x2;;;S-1-15-2-1)(A;;0xf0007;;;SY)(A;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;0x7;;;BA)(A;;0x7;;;SO)(A;;0x3;;;IU)(A;;0x3;;;SU)(A<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;;0x3;;;S-1-5-3)(A;;0x3;;;S-1-5-33)(A;;0x1;;;S-1-5-<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;32-573)<\/p>\n<p style=\"margin-left:30px\">LogFilePath&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : %SystemRoot%\\System32\\Winevt\\Logs\\Microsoft-Windows<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -WinRM%4Operational.evtx<\/p>\n<p style=\"margin-left:30px\">MaximumSizeInBytes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 1052672<\/p>\n<p style=\"margin-left:30px\">LogMode&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Circular<\/p>\n<p style=\"margin-left:30px\">OwningProviderName &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: Microsoft-Windows-WinRM<\/p>\n<p style=\"margin-left:30px\">ProviderNames&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : {Microsoft-Windows-WinRM}<\/p>\n<p style=\"margin-left:30px\">ProviderLevel&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :<\/p>\n<p style=\"margin-left:30px\">ProviderKeywords&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :<\/p>\n<p style=\"margin-left:30px\">ProviderBufferSize&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 64<\/p>\n<p style=\"margin-left:30px\">ProviderMinimumNumberOfBuffers : 0<\/p>\n<p style=\"margin-left:30px\">ProviderMaximumNumberOfBuffers : 64<\/p>\n<p style=\"margin-left:30px\">ProviderLatency&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 1000<\/p>\n<p style=\"margin-left:30px\">ProviderControlGuid&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :<\/p>\n<p style=\"margin-left:30px\">To disable the log, I set it to false. This command appears here:<\/p>\n<p style=\"margin-left:30px\">Get-WinEvent -ListLog *winrm* | % {echo y | wevtutil.exe sl $_.LogName \/e:false}<\/p>\n<p>And, I can check the output once again with this command:<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; (Get-WinEvent -ListLog *winrm*).isenabled<\/p>\n<p style=\"margin-left:30px\">False<\/p>\n<p>I obviously don&rsquo;t want to do all this typing, so I can put these commands in a script easily, or I can create a function and add them to a module. The cool thing is that I can also add other logs. I can even run the commands remotely by using Windows PowerShell remoting (assuming that you get it working).<\/p>\n<p>TB, that is all there is to using Windows PowerShell to help troubleshoot your WinRM connection.&nbsp; Join me tomorrow when I will talk about more cool stuff.<span style=\"font-size:12px\">&nbsp;<\/span><\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Ed Wilson, Microsoft Scripting Guy, talks about using Windows PowerShell to look at WinRM logs. &nbsp;Hey, Scripting Guy! I am having problems with WinRM. When I use the Get-CimInstance cmdlet, it fails. When I specify the &ndash;DCOM protocol for Get-CimInstance, it works. I suspect I have a WinRM problem. How can I go about [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[622,3,134,45,620],"class_list":["post-72941","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-events-and-logging","tag-scripting-guy","tag-troubleshooting","tag-windows-powershell","tag-winrm"],"acf":[],"blog_post_summary":"<p>Summary: Ed Wilson, Microsoft Scripting Guy, talks about using Windows PowerShell to look at WinRM logs. &nbsp;Hey, Scripting Guy! I am having problems with WinRM. When I use the Get-CimInstance cmdlet, it fails. When I specify the &ndash;DCOM protocol for Get-CimInstance, it works. I suspect I have a WinRM problem. How can I go about [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/72941","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=72941"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/72941\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=72941"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=72941"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=72941"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}