Create a custom object with desired properties. Use New-Object to create one. Use Add-Member to add noteproperty
members to the object. Get data with WMI (Get-WmiObject - alias gwmi
) and populate object's properties with those.
Collect objects into an array and export it as CSV with Export-Csv.
Try it like so,
$computers = @("System1", "System2") # An array of computer names.
$arr = @() # Array for CSV export
foreach($comp in $computers){
$o = new-object psobject # New object
# Add Owner property and set its value with a WMI call
$o | add-member -membertype noteproperty -name Owner -value (gwmi win32_computersystem -computername $comp).PrimaryOwnerName
# Ditto for Serial property
$o | add-member -membertype noteproperty -name Serial -value (gwmi win32_bios -computername $comp).SerialNumber
$arr += $o
}
# Export the object data as CSV
$arr | select -property Owner,Serial | export-csv -notypeinformation c:\temp\ownerdata.csv