title: Powershell GWMI win32_operatingsystem trim output
body: <p>When you use</p>
  
  <pre><code>(GWMI -ComputerName $server -Class Win32_OperatingSystem -ErrorAction Stop).Caption
  </code></pre>
  
  <p>to get captions like</p>
  
  <pre class="lang-none prettyprint-override"><code>Microsoft(R) Windows(R) Server 2003 Standard x64 Edition
  Microsoft Windows Server 2008 R2 Standard
  Microsoft Windows Server 2012 Datacenter
  </code></pre>
  
  <p>What's an easy way to remove <code>"Microsoft Windows"</code> and <code>"Microsoft(R) Windows"</code> from the results?</p>
  
  <p>I have come up with:</p>
  
  <pre><code>(GWMI Win32_OperatingSystem -Comp $server).Caption -Replace "^Microsoft Windows "
  </code></pre>
  
  <p>Which turns <code>"Microsoft Windows Server 2012 Datacenter"</code> into <code>"Server 2012 Datacenter"</code>, but the old machines on 2003 and 2008 don't match the replace regex.</p>