title: How do I find the Collection Membership Information with PowerShell
body: <p>I have the following code, but I get an "Invalid Namespace" error constantly, I am pretty sure I am entering the correct information.</p>
  
  <p>If you have another way of doing this, it's also accepted.</p>
  
  <pre><code>Param(
      $SiteCode,
      $SourceFile,
      $Destination = "$env:USERPROFILE\DESKTOP\Computers.csv"
  )
  
  
  $Computers = Get-Content $SourceFile
  $EmptyArray = @()
  
  foreach($computer in $computers)
  {
      $ResourceIDQuery = Get-WmiObject -Namespace "root\sms\site_$SiteCode" -Class SMS_R_SYSTEM -Filter "Name='$computer'"
  
      $CollectionQuery = Get-WmiObject -Namespace "root\sms\site_$SiteCode" -Class SMS_CollectionMember_a -filter "ResourceID='$($ResourceIDQuery.ResourceId)'"
  
      foreach($Item in $CollectionQuery)
      {
          $DObject = New-Object PSObject
              $Dobject | Add-Member -MemberType NoteProperty -Name "Computer" -Value $computer 
              $Dobject | Add-Member -MemberType NoteProperty -Name "ResID" -Value $($ResourceIDQuery.ResourceId)
              $Dobject | Add-Member -MemberType NoteProperty -Name "CollID" -Value $($Item.CollectionId)
              $Dobject | Add-Member -MemberType NoteProperty -Name "DirectOrNot" -Value $($Item.IsDirect)
          $EmptyArray += $Dobject
      }
  }
  
  $EmptyArray | ConvertTo-Csv -NoTypeInformation | Out-File $Destination
  </code></pre>