title: How to read a string from text file using powershell
body: <p>I want to read a specific string from a text file and output the string into another text file.</p>
  
  <p>My text file (Sample.txt) looks like below:</p>
  
  <pre><code>@{AssemblyName=Microsoft.Office.Excel, Version=1.0.0.0, Culture=neutral,     PublicKeyToken=1y08bdf1111e0105c; Path=C:\Tes\app1\cc\application; ProjectPath=C:\test\application\Application.vbproj; Name=Microsoft.Office.Excel}
  
  @{AssemblyName=System; Path=C:\Tes\app2\ser\application; ProjectPath=C:\test\application2\Application.vbproj; Name=System}
  </code></pre>
  
  <p>I do not want to include anything except the assemblyname.. i.e, the script should not consider version, culture etc.</p>
  
  <p>The text file has lot of such assembly information.
  I would like to read only the <strong>AssemblyName</strong> and write that to another text file in powersehll.
  For Ex: The output.txt should contain only <strong>Microsoft.Office.Excel</strong>. <br></p>
  
  <p><strong>Also, I want to exclude few assembly names that start with a specific string like for eg: System</strong>. How can I do that?</p>
  
  <p>I tried below, but it's not writing anything to the output.txt. <br></p>
  
  <pre><code>$workdir = "C:\Test"
  $Txt = "$workdir\Sample.txt"
  
  Function GetAsmName($rTxt)
  {
  
  Get-Content $Txt
  
  $regex = '@{AssemblyName="(\w*?)"[,|;]'
  $matches = (select-string  -Path $Txt -Pattern $regex)
  $matches | Select -Expandproperty Matches | Select @{n="Name";e={$_.Groups[1].Value}}
  Set-Content -path $workdir\Output.txt -value $matches
  }
  </code></pre>
  
  <p>Any help would be greatly appreciated.<br></p>
  
  <p>Thanks <br></p>