title: How to fix this Powershell script using Get-WmiObject?
body: <p>I have this piece of code that gets the information from the computers in the domain and outputs to a csv file. I tried to add a new line of code to also grab t he Disk information for the computers but I can't get it working as expected. </p>
  
  <pre><code># Get the list of all computer names and export to CSV file
  Get-ADComputer -Filter * | select Name | Export-Csv -Path 'C:\temp\computers.csv' -NoTypeInformation
  
  # Import the computer names from CSV file and get the system information
  $computers = Import-Csv “C:\Temp\computers.csv” | ForEach {
  
      $computerSystem = Get-WmiObject Win32_ComputerSystem -ComputerName $_.Name
      $computerOS = Get-WmiObject Win32_OperatingSystem -ComputerName $_.Name
      $computerCPU = Get-WmiObject Win32_Processor -ComputerName $_.Name
      $computerSN = Get-WmiObject Win32_bios -ComputerName $_.Name | Select-Object SerialNumber
      $computerDisk = Get-WmiObject win32_logicaldisk -ComputerName $_.Name | Select-Object DeviceId
  
      [PSCustomObject]@{
          'PCName' = $computerSystem.Name    
          'Model' = $computerSystem.Model   
          'RAM' = "{0:N2}" -f ($computerSystem.TotalPhysicalMemory/1GB)    
          'CPU' = $computerCPU.Name    
          'OS' = $computerOS.caption   
          'SN' = $computerSN.SerialNumber
          'User' = $computerSystem.UserName 
          'Disk' = $computerDisk.DeviceId | Format-Table DeviceId, MediaType, @{n="Size";e={[math]::Round($_.Size/1GB,2)}},@{n="FreeSpace";e={[math]::Round($_.FreeSpace/1GB,2)}}
      }
  
  } | Export-Csv 'C:\Temp\system-info.csv' -NoTypeInformation
  </code></pre>
  
  <p>This is the line of codes for disk. </p>
  
  <pre><code>$computerDisk = Get-WmiObject win32_logicaldisk -ComputerName $_.Name | Select-Object DeviceId
  </code></pre>
  
  <p>And...</p>
  
  <pre><code>'Disk' = $computerDisk.DeviceId | Format-Table DeviceId, MediaType, @{n="Size";e={[math]::Round($_.Size/1GB,2)}},@{n="FreeSpace";e={[math]::Round($_.FreeSpace/1GB,2)}}
  </code></pre>
  
  <p>The other parameters work but only the disk info section isn't working. the output is: <code>System.Object[]</code> instead of displaying the info .</p>