title: Powershell: Unexpected token
body: <p>This must be something obvious, but I can't get this to work. I'm trying to transmit objects that should used to build $classKey which in turn lead to delete the desired software (amd64 or i386). Well, here the code:</p>
  
  <pre><code>$name = @("softwareName1", "softwareName2", "softwareName3")
  $strComputer = "localhost"
  $getWmiClass = get-wmiobject -class "SampleProductsList32" -namespace "root\DEFAULT" -computername $strComputer | select-object IdentifyingNumber, Displayname, DisplayVersion 
  $getWmiClass2 = get-wmiobject -class  "SampleProductsList" -namespace "root\DEFAULT" -computername $strComputer | select-object IdentifyingNumber, Displayname, DisplayVersion 
  foreach ($AppDisplayName in $name) {
      $GetWmiClass $GetWmiClass2 | % {
          % ($DispName in $_) {
              if($DispName.DisplayName -eq $AppDisplayName) {
                  $classKey += "IdentifyingNumber=`"`{${DispName.IdentifyingNumber}`}`",Name=`"${DispName.Displayname}`",version=`"${DisplayVersion}`""
                  ([wmi]"\\$server\root\cimv2:Win32_Product.$classKey").uninstall()
              }
          }
      }
  }
  </code></pre>
  
  <p>I rewrote code (added a filter) but it didn't help.</p>
  
  <pre><code>filter GetApps {
      foreach ($DispName in $_) {
          if($DispName.DisplayName -eq $AppDisplayName) {
              $classKey += "IdentifyingNumber=`"`{${DispName.IdentifyingNumber}`}`",Name=`"${DispName.Displayname}`",version=`"${DisplayVersion}`""
              ([wmi]"\\$server\root\cimv2:Win32_Product.$classKey").uninstall()
          }
      }
  }
  $name = @("softwareName1", "softwareName2", "softwareName3")
  $strComputer = "localhost"
  $getWmiClass = get-wmiobject -class "SampleProductsList32" -namespace "root\DEFAULT" -computername $strComputer | select-object IdentifyingNumber, Displayname, DisplayVersion 
  $getWmiClass2 = get-wmiobject -class  "SampleProductsList" -namespace "root\DEFAULT" -computername $strComputer | select-object IdentifyingNumber, Displayname, DisplayVersion 
  foreach ($AppDisplayName in $name) { $GetWmiClass $GetWmiClass2 | GetApps }
  </code></pre>
  
  <p>Here the error message:</p>
  
  <pre><code>Unexpected token 'GetWmiClass2' in expression or statement.
  At line:2 char:31
  +     $GetWmiClass $GetWmiClass2 &lt;&lt;&lt;&lt;  | % {
      + CategoryInfo          : ParserError: (GetWmiClass2:String) [], ParentContainsErrorRecordException
      + FullyQualifiedErrorId : UnexpectedToken
  </code></pre>