<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>grokgarble.com &#187; WinRM</title>
	<atom:link href="http://jeffmurr.com/blog/?cat=13&#038;feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://jeffmurr.com/blog</link>
	<description>Database, Software, and System Engineering</description>
	<lastBuildDate>Tue, 26 Sep 2017 19:07:40 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.9.30</generator>
	<item>
		<title>WinRM for an Environment Simplified</title>
		<link>http://jeffmurr.com/blog/?p=178</link>
		<comments>http://jeffmurr.com/blog/?p=178#comments</comments>
		<pubDate>Fri, 02 Aug 2013 22:28:44 +0000</pubDate>
		<dc:creator><![CDATA[Jeff Murr]]></dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[WinRM]]></category>

		<guid isPermaLink="false">http://jeffmurr.com/blog/?p=178</guid>
		<description><![CDATA[Windows Remote Management (WinRM) is the Microsoft implementation of WS-Management Protocol.  In many key items within the latest offerings from Microsoft management, included most obviously for me, PowerShell, it is the under pinning of many of the remote management operations. The idea is a good one.  Align with a standard in your latest technologies methods used to manage [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Windows Remote Management (<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa384426(v=vs.85).aspx">WinRM</a>) is the Microsoft implementation of <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa384470(v=vs.85).aspx">WS-Management Protocol</a>.  In many key items within the latest offerings from Microsoft management, included most obviously for me, <a href="http://technet.microsoft.com/en-us/library/bb978526.aspx">PowerShell</a>, it is the under pinning of many of the remote management operations.</p>
<p>The idea is a good one.  Align with a standard in your latest technologies methods used to manage yourself, making you more usable by others.</p>
<p>In this post I&#8217;ll offer a quick WinRM configuration PowerShell script to get this feature configured on a Windows 2008, R2, and Windows 2012 server.  I&#8217;ll also offer feedback on the security objection and what I think is the best solution for a native Windows environment since I&#8217;ve hand to handle these often in my line of work.</p>
<p><strong>Configuration Simplified</strong></p>
<p>Get right to it for those not wanting to read any more.  Open a PowerShell Console as Administrator on both the client and server, servers and execute:</p>
<pre class="brush:powershell">Write-Host "Configuring WinRM for remote deployment..."
Enable-PSRemoting -Force 
winrm set winrm/config/client `@`{TrustedHosts=`"*`"`}</pre>
<p><strong>More detail&#8230;</strong></p>
<p>For PowerShell, WinRM is the basis of many cmdlets performing remote commands and tasks.  This includes <a href="http://technet.microsoft.com/en-us/library/hh849707.aspx">Enter-PSSession</a> and <a href="http://technet.microsoft.com/en-us/library/hh849719.aspx">Invoke-Command</a>.  These cmdlets offer powerful abilities to perform tasks on a remote computer both synchronously and in parallel, asynchronously to an array object of server names.</p>
<p>Believe it or not (from this <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa384372(v=vs.85).aspx">lengthy </a>write up), Microsoft wanted taking advantage of the protocol easier and less of a burden to implement.  As a result, <strong>WinRM.exe</strong> comes with a &#8220;-<strong>quickconfig</strong>&#8221; option for quick local configuration of itself, complete with a set of Microsoft&#8217;s best practice defaults.  Almost too good, and I&#8217;ll get to that below.</p>
<p>Therefore, the easiest thing to do is to go to a cmd prompt as an admin and run to get it all started:</p>
<pre class="brush:shell">WinRM quickconfig</pre>
<p>This will set up your local service with everything to get started.  Essentially, turning on the lights.</p>
<p>Powershell&#8217;s flavor of this command is rolled up into  <a href="http://technet.microsoft.com/library/hh849867.aspx">Set-WSManQuickConfig</a>.  However, these both only modify the config of the service.  For the windows firewall, Microsoft gave us another cmdlet that&#8217;s a wrapper for <a href="http://technet.microsoft.com/library/hh849867.aspx">Set-WSManQuickConfig</a>.  <a href="http://technet.microsoft.com/en-us/library/hh849694.aspx">Enable-PSRemoting</a> cmdlet performs a few other functions as well as executing the <a href="http://technet.microsoft.com/library/hh849867.aspx">Set-WSManQuickConfig</a>.  Things like configuring the Windows firewall (in 2.0 it creates the exception, in 3.0 it creates a rule).</p>
<p>If you ride the defaults of these configurations with regards to network port, any external firewalls between your client and server will need to allow tcp 5986 bidirectional for WinRM 2.0 and above, 443 for WinRM 1.1.</p>
<p>Even after you run the &#8220;<strong>WinRM -quickconfig</strong>&#8221; or &#8220;<strong>Enable-PSRemoting&#8221;</strong>, you&#8217;ll find commands attempted remotely like <strong>Invoke-Command</strong> or <strong>Enter-PSSession</strong> will still fail complaining about a configuration error.  The reason is that you&#8217;ve only turned on the lights, you haven&#8217;t told the bouncer who is allowed in.  Be default, these tools do not trust anyone to connect other than&#8230;localhost.  The list of allowed servers is listed in the &#8220;<em><strong>TrustedHost</strong></em>&#8221; property of WinRM configuration.  Both of these tools the default <strong>TrustedHost</strong> list is blank.</p>
<p>Therefore, lets get back to the PowerShell.  Its a quick and dirty solution that&#8217;s wide open and will that need to be executed on both machines you want to configure to talk remote to one another:</p>
<pre class="brush:powershell">Write-Host "Configuring WinRM for remote deployment..."
Enable-PSRemoting -Force 
winrm set winrm/config/client `@`{TrustedHosts=`"*`"`} 
winrm set winrm/config/winrs `@`{MaxMemoryPerShellMB=`"2048`"`}</pre>
<p>As you can guess, &#8220;*&#8221; is everyone and may not be good enough for your needs.  Below we discuss more security aspects of a quick configuration.</p>
<p><strong>Locking it down</strong></p>
<p>There are complex scripts on the internet that allow for the setup of servers, even doing it <a href="http://gallery.technet.microsoft.com/scriptcenter/Enable-PSRemoting-Remotely-6cedfcb0">remotely</a>.  Out of the box both the WinRM and the cmdlets leave you with blank <strong>TrustedHosts</strong>.  Servers that will send or receive commands from other hosts must either have a white listed &#8220;*&#8221; or the specific servernames/IP in this list before you can connect.</p>
<p>The next script creates a list of servers passed as a CSV file and establishes it as your <strong>TrustedHost</strong> property.  As long as a column within your CSV file contains &#8220;Server&#8221; as a heading, those values will be included in the trusted hosts configuration and applied to the machine&#8217;s <strong>TrustedHost </strong>configuration of WinRM.</p>
<pre class="brush:powershell">param(
	[Parameter(Position=0, Mandatory=$true)]
	[ValidateNotNullOrEmpty()]
	[System.String]
	$CSVFilePath
)

function Get-ServerList {
	param(
		$CSVFilePath
	)

	$Servers = Import-Csv $CSVFilePath
	$Servers | % {$List += $_.Server + ","}

	Return $List.Substring(0,$List.Length - 1)

}

function Configure-WinRM {
	param(
		$ServerList
	)
	Write-Host "Configuring WinRM for remote deployment..."
	Enable-PSRemoting -Force 
	winrm set winrm/config/client `@`{TrustedHosts=`"$ServerList`"`}  
	winrm set winrm/config/winrs `@`{MaxMemoryPerShellMB=`"2048`"`}
}

Configure-WinRm -ServerList $(Get-ServerList -CSVFilePath $CSVFilePath)</pre>
<p><strong>Note:</strong>  In both examples within the explanation, I&#8217;ve up the <strong>MaxMemoryPerShellMB</strong>.  This is optional; however, I&#8217;ve found that many tools that I may need or objects that I create are heavier than the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ee309367(v=vs.85).aspx">default 150 MB</a> amount.  I&#8217;ve found that upping it to 2048 will mitigate my running out of remote memory during processing large commands like regasm or installation packages.  Mis-configuration usually results in an obfuscated -1 exit code or just instability.  It wasn&#8217;t until I popped open process explorer that I found I was hitting a limit that most bigger executables require more of.  Totally up to you, but it is part of my server buildout now along with a correct server.csv list and features.</p>
<p><strong>The Remaining Security Concerns (For Windows Environments)</strong></p>
<p><strong>TrustedHosts</strong> means only these computers can connect.  Security engineers will wonder what those connections are passing, even if its in a protected zone, between the servers listed and if that&#8217;s secure.</p>
<p>First the obvious, SSL is an option for WinRM.  However, I caution configuring it if your talking Windows to Windows. When asked, if you should configure SSL for security loving systems folks it can be tempting to think it is better.  The balance between and security, support and use is something we all have to deal with constantly.  In banking and healthcare it constantly audited, as it should be and I understand, layers is the answer to security.  But, WinRM with <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa384291(v=vs.85).aspx">WS-Management</a> encrypts all content transmitted over the network using Kerberos and these NTLM (machine) keys.  With Windows, a minimum of 128 bit encryption (Windows 7/2008 and up) is already in place with most later OS&#8217;s pushing the AES 256 button now.</p>
<p>The only thing that HTTPS will do is encrypt commands <strong><em>differently, that can be watered down</em></strong>.  Not to mention give a shelf life to your configuration the length of the validity of your certificates, before they expire.  I applaud the extensiblility, but its truly overkill in a windows environment and making something that needs to remain easy too complex; hence me leaving it out of the configuration and discussing it here.</p>
<p>Now, if you&#8217;re leaving a Windows environment, yes; install and configure if you&#8217;re using a non Windows product to manage a Windows machine.  That&#8217;s part of the the initiative behind WS-Management, uniform cross platform communication.  Everyone OS doesn&#8217;t have the same encryption methods as Windows baked in.  For that, I&#8217;ll have to cover another day.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div data-counters='1' data-style='square' data-size='regular' data-url='http://jeffmurr.com/blog/?p=178' data-title='WinRM for an Environment Simplified' class='linksalpha_container linksalpha_app_3'><a href='//www.linksalpha.com/share?network='facebook' class='linksalpha_icon_facebook'></a><a href='//www.linksalpha.com/share?network='twitter' class='linksalpha_icon_twitter'></a><a href='//www.linksalpha.com/share?network='googleplus' class='linksalpha_icon_googleplus'></a><a href='//www.linksalpha.com/share?network='mail' class='linksalpha_icon_mail'></a></div><div data-position='' data-url='http://jeffmurr.com/blog/?p=178' data-title='WinRM for an Environment Simplified' class='linksalpha_container linksalpha_app_7'><a href='//www.linksalpha.com/share?network='facebook' class='linksalpha_icon_facebook'></a><a href='//www.linksalpha.com/share?network='twitter' class='linksalpha_icon_twitter'></a><a href='//www.linksalpha.com/share?network='googleplus' class='linksalpha_icon_googleplus'></a><a href='//www.linksalpha.com/share?network='mail' class='linksalpha_icon_mail'></a></div>
<!-- NgfbSharing::get_buttons content filter skipped: buttons not allowed in rss feeds -->
]]></content:encoded>
			<wfw:commentRss>http://jeffmurr.com/blog/?feed=rss2&#038;p=178</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
