title: Removing text in a string between two characters using Powershell
body: <p>I have a powershell script that runs and collects information and puts it in a .csv file.  A sample of the information looks like what is listed below, with each line starting with a unique server name followed by a random unique identifier in contained a pair of ( ). </p>
  
  <pre><code>"GDR01W01SQ004 (e785754f-eeb1)","1","4","63","NY-TER-PLN-P-5N"
  "GDR01L02D001 (4b889a4d-d281)","4","12","129","CO-FDP-STE-NP-5N"
  </code></pre>
  
  <p>I have a second powershell script that runs and takes this .csv file and its information and formats it into a report with a header and proper spacing.</p>
  
  <p>Can someone please assist me with removing the text in between the ( ) as well as the ( )?</p>
  
  <p>I would like the entries for each line to look like the following:</p>
  
  <pre><code>"GDR01W01SQ004","1","4","63","NY-TER-PLN-P-5N"
  </code></pre>
  
  <p>Thank you very much in advance!</p>
  
  <p>Here is the script I have been using.</p>
  
  <pre><code>####################PowerCLI Check####################
  
  # Verify whether the PowerCLI module is loaded, if not load it.
  if ( (Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) -eq $null )
  {
      Add-PsSnapin VMware.VimAutomation.Core -ErrorAction Stop
  }
  
  
  
  
  ################### Run Time Section ####################
  #This script should be run from a server that has DNS records for all entries in vcenters.txt
  $file = get-Content c:\reports\vcenter\vcenters.txt  
  
  foreach ( $server in $file) { 
  Connect-VIserver -Server $server
  
  Get-VM | select Name, NumCpu, MemoryGB, ProvisionedSpaceGB, Notes | Out-Null
  
  } 
  
  
  # Command for Custom Annotations.
  Get-VM | select Name, NumCpu, MemoryGB, ProvisionedSpaceGB, Notes -expandproperty customfields  | Export-Csv -path “c:\reports\vcenter\vcenall.csv” -NoTypeInformation
  
  # Takes vcenall.csv and sorts only the Name and Notes columns and selects all but the custom fields. Capacity Reporting script caprep.ps1 runs against this csv.
  Import-csv c:\reports\vcenter\vcenall.csv | Sort-Object Notes, Name | Select-Object Name, NumCpu, MemoryGB, ProvisionedSpaceGB, Notes |Export-csv capacity.csv -NoTypeInformation
  
  #Used to remove domain from server name
  (Get-Content capacity.csv) | ForEach-Object { $_ -replace ".domain.local", "" } | Set-Content capacity.csv
  
  
  # Takes vcenall.csv and sorts only the Notes column and selects only the Name and Notes columns. Nimsoft comparison script nimcomp.ps1 runs against this csv.
  Import-csv c:\reports\vcenter\vcenall.csv | Sort-Object Notes | Select-Object Name, Notes | Export-csv nimsoft.csv -NoTypeInformation
  
  # Takes vcenall.csv and sorts only the Name columns and exports all fields. Backup/Restore comparison script bure.ps1 runs against this csv.
  Import-csv c:\reports\vcenter\vcenall.csv | Sort-Object Name | Export-csv bure.csv -NoTypeInformation
  </code></pre>