Import-Module ActiveDirectory
$computers = Get-ADComputer -Filter * -SearchBase "OU=workstations,DC=company,DC=org" |
Select-Object -Expand Name
$wmiObjs = Get-WmiObject -Class Win32_ComputerSystem -Property Name, Model -ComputerName $computers |
select Name, Model |
Export-Csv c:\temp\workstations-models.csv
I am getting errors like the below which I would like to have placed into the CSV as well and with txt it is down with PC name:
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA) At line:3 char:12 + $wmiObjs = Get-WmiObject -Class Win32_ComputerSystem -Property Name, ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand