title: Remove string after specific character from list using powershell
body: <p>I am attempting to clean up (reformat) a list of servers that has been provided to me containing the full domain name so that I can use it elsewhere. The list of servers arrive formatted like: servername.domain.com. I read the list into a variable using import-csv and remove the other columns of data not needed using the format-table command. My resulting command looks something like this:</p>
  
  <pre><code>$l=Import-Csv .\filename.csv | Format-Table TARGET
  </code></pre>
  
  <p>TARGET is the column name containing the server names.</p>
  
  <p>When I use the following to remove the domain name portion of the server name, the resulting value is "Microsoft" repeated for each line containing the server name. I have confirmed the server names are being read into the variable correctly.</p>
  
  <pre><code>$l -replace '(.+?)\..+','$1'
  </code></pre>
  
  <p>The command does work if there is only one server name in the variable. I know I was able to trim the names of the servers down at one point but I think I had a brain lapse that day and just did not write down the command I used. :(</p>
  
  <p>Any suggestions? My end goal is to incorporate the commands into a script for scheduled processing.  </p>