My output file has unnecessary information

Hello,
I have created a script to do an inventory of some workstations. It works great beyond the output csv I am getting. Here is the script:

#runs this script on a specific OU for machines in domain:

$computers = Get-ADComputer -Filter * -SearchBase "ou=Test,ou=Users,ou=SubOU,ou=Main OU,dc=domain,dc=local" | Select-Object -ExpandProperty Name

$results = foreach ($computer in $computers) {
    $Info = Get-CimInstance -ComputerName $computer -ClassName Win32_ComputerSystem | 
Select-Object -ExpandProperty Name
    $LastUser = Get-CimInstance -ComputerName $computer -ClassName 
 Win32_ComputerSystem | Select-Object -ExpandProperty UserName
    $OperatingSystem = Get-CimInstance -ComputerName $computer -ClassName Win32_OperatingSystem | Select-Object -Property Caption, OSArchitecture
    $Serial = Get-CimInstance Win32_bios -ComputerName $computer | Select serialnumber
    $Manufacturer = Get-CimInstance Win32_bios -ComputerName $computer | Select Manufacturer
    $Model = Get-CimInstance -Class CIM_ComputerSystem -ComputerName $computer | Select Model


    $OutputObj = New-Object -Type PSObject
    $OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Info
    $OutputObj | Add-Member -MemberType NoteProperty -Name UserName -Value $LastUser
    $OutputObj | Add-Member -MemberType NoteProperty -Name OperatingSystem -Value $OperatingSystem
    $OutputObj | Add-Member -MemberType NoteProperty -Name SerialNumber -Value $Serial 
    $OutputObj | Add-Member -MemberType NoteProperty -Name Manufacturer -Value $Manufacturer
    $OutputObj | Add-Member -MemberType NoteProperty -Name Model -Value $Model

    $OutputObj
}

$results | Export-Csv -Path 'C:\Scripts\ADScripts\CIMIventory.csv' -NoTypeInformation

Here is the output:

Column 1 Column 2 Column 3 Column 4
ComputerName OperatingSystem SerialNumber Model
My Test PC @{Caption=Microsoft Windows 11 Pro; OSArchitecture=64-bit} @{serialnumber=Myserial#} @{Model=HP ProDesk 405 G6 Desktop Mini PC}
1 Like

Notice in Column 2, 3 and 4 there are @{caption= , @{serialnumber= , @{Model=

Any ideas why that would be and how I can remove that?
Thanks!

1 Like

That’s because you’re selecting multiple properties so you get a PSCustomObject. You would need to join the strings together to get a single string.

$OutputObj | Add-Member -MemberType NoteProperty -Name OperatingSystem -Value $("{0} : {1}" -f $OperatingSystem.Caption, $OperatingSystem.OSArchitecture)
1 Like

That definitely makes sense for the Operating System line since there are two properties. But, what about where I am only selecting a single property like “Manufacturer”?

1 Like

Because you’re still referencing a PSCustomObject. You need to reference the noteproperties in your Add-Member statements so serial should be

-Value $Serial.serialNumber
1 Like

Ok, I learned something today. lol! That did the trick
Thanks!!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.