title: Parsing and removing text with cmd or powershell
body: <p>I've checked quite a few other questions here but was unable to find what I need. I am currently trying to automate the process of finding out what VMs are in what Hyper V servers. Here is my current script.</p>
  
  <pre><code>@echo off
  set /P dc= "Which DC do you want? " 
  dsquery computer -name %DC%VUT* &gt; dsquery.txt
  type dsquery.txt | findstr /v IMAGINGOU | findstr /v OTHEROU &gt; dsquery2.txt
  powershell -command Get-Content dsquery2.txt | ForEach-Object { $_ -replace '"CN=', "" } | Set-Content dsquery3.txt
  powershell -command Get-Content dsquery3.txt | ForEach-Object { $_ -replace ',OU=CAM,OU=Exchange,OU=Server,DC=RED001,DC=local"', "" } | Set-Content serverlist.txt
  powershell -command .\Get-HyperVMod.ps1 -file output.csv
  </code></pre>
  
  <p>The problem I have hit is the servers that I can do dsquery from (Win2k3) can't do the ForEach-Object because they have an older version of Powershell and the Win2k8 servers that can do the ForEach-Object can't do a dsquery.</p>
  
  <p>Here is a sample of the dsquery output that I am trying to parse and remove all but the server name.</p>
  
  <pre><code>"CN=SERVER001,OU=VUT,OU=Infastructure,OU=Server,DC=dcname,DC=local"
  "CN=SERVER008,OU=ImagingWDS,DC=red002,DC=local"
  </code></pre>
  
  <p>Output should be</p>
  
  <pre><code>SERVER001
  SERVER008
  </code></pre>
  
  <p>Any suggestions on either doing this with another method or just my small problem of removing the extra text from the file.</p>