System.Object when exporting to CSV

Hello Everyone!

 

First off, please note that I am self-taught when it comes to Powershell, so please forgive me if my question seems obvious.

 

I am trying to gather some system information using the following script(and again, my apologies for literally copying/pasting the script into the thread):

 

$exportLocation = ‘C:\Users\Nik\Documents\pcInventory2.csv’

$Bios = Get-WmiObject win32_bios
$hardware = Get-WmiObject win32_computersystem
$sysbuild = Get-WmiObject win32_wmiSetting
$OS = Get-WmiObject win32_OperatingSystem
$networks = Get-WmiObject win32_NetworkAdapterConfiguration | Where-Object {$. IPEnabled}
$drivespace = Get-WmiObject win32_volume -Filter ‘drivetype = 3’ |
Select-Object PScomputername, driveletter | Where-Object { $
.driveletter -match ‘C:’ }
$cpu = Get-WmiObject win32_Processor
$username = Get-ChildItem “C:\Users” | Sort-Object LastWriteTime -Descending | Select-Object name, LastWriteTime
$totalMemory = [math]::round($hardware.TotalPhysicalMemory/1024/1024/1024, 2)
$lastBoot = $OS.ConvertToDateTime($OS.LastBootUpTime)

$IPAddress = $networks.IpAddress[0]
$MACAddress = $networks.MACAddress
$systemBios = $Bios.serialnumber

$outputObj = New-Object -Type PSObject
$outputObj | Add-Member -MemberType NoteProperty -Name Manufacture -Value $Hardware.Manufacture
$outputObj | Add-Member -MemberType NoteProperty -Name Model -Value $Hardware.Model
$outputObj | Add-Member -MemberType NoteProperty -Name Processor_Type -Value $cpu.Name
$outputObj | Add-Member -MemberType NoteProperty -Name System_Type -Value $hardware.SystemType
$outputObj | Add-Member -MemberType NoteProperty -Name Operating_System -Value $OS.Caption
$outputObj | Add-Member -MemberType NoteProperty -Name Operating_System_Version -Value $OS.version
$outputObj | Add-Member -MemberType NoteProperty -Name Operating_System_BuildVersion -Value$sysbuild.BuildVersion
$outputObj | Add-Member -MemberType NoteProperty -Name Serial_Number -Value $systemBios
$outputObj | Add-Member -MemberType NoteProperty -Name IP_Address -Value $IPAddress
$outputObj | Add-Member -MemberType NoteProperty -Name MAC_Address -Value $MACAddress
$outputObj | Add-Member -MemberType NoteProperty -Name Last-User -Value $username.Name
$outputObj | Add-Member -MemberType NoteProperty -Name User_Last_Login -Value $username.LastWriteTime
$outputObj | Add-Member -MemberType NoteProperty -Name C:_FreeSpace_GB -Value $drivespace.GBfreespace
$outputObj | Add-Member -MemberType NoteProperty -Name Total_Memory_GB -Value $totalMemory
$outputObj | Add-Member -MemberType NoteProperty -Name Last_ReBoot -Value $lastboot
$outputObj | Export-Csv $exportLocation -Append -NoTypeInformation

 

 

When I export this into a CSV file, I get most of the information, except for: Processor_Type, Last_User and Last_User_Login. These display as system.object.

 

Can anyone help me resolve this?

Thank you!

 

I “streamlined” your code a little bit and formatted it as code … I hope you don’t mind. :wink:

$OutputFile = 'C:\Users\Nik\Documents\pcInventory2.csv'

$OS = Get-CimInstance -ClassName Win32_OperatingSystem
$cpu = Get-CimInstance -ClassName win32_Processor
$Bios = Get-CimInstance -ClassName Win32_BIOS
$username = Get-ChildItem 'C:\Users' | Sort-Object -Property LastWriteTime -Descending | Select-Object -First 1 -Property name, LastWriteTime
$networks = Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration | Where-Object { $_.IPEnabled }
$hardware = Get-CimInstance -ClassName CIM_ComputerSystem
$sysbuild = Get-CimInstance -ClassName  Win32_WMISetting
$drivespace = Get-CimInstance -ClassName Win32_Volume -Filter 'drivetype = 3' |
    Where-Object { $_.driveletter -match 'C:' }


$Result = [PSCustomObject]@{
    Manufacture                   = $Hardware.Manufacturer
    Model                         = $Hardware.Model
    Processor_Type                = $cpu[0].Name
    System_Type                   = $hardware.SystemType
    Operating_System              = $OS.Caption
    Operating_System_Version      = $OS.version
    Operating_System_BuildVersion = $sysbuild.BuildVersion
    Serial_Number                 = $Bios.serialnumber
    IP_Address                    = $networks.IpAddress[0]
    MAC_Address                   = $networks.MACAddress[0]
    Last                          = $username.Name
    User_Last_Login               = $username.LastWriteTime
    C_FreeSpace_GB                = [math]::round($drivespace.FreeSpace / 1024 / 1024 / 1024, 2)
    Total_Memory_GB               = [math]::round($hardware.TotalPhysicalMemory / 1024 / 1024 / 1024, 2)
    Last_ReBoot                   = $os.LastBootUpTime
}

$Result | Export-Csv -Path $OutputFile -NoTypeInformation

Haha thank you, Olaf! Is it obvious i’m still new to all of this? I’ll try that out and see if it works for me!

Okay, I ran the code and now the only section that is still returning system.object is “processor type”

Is it a server with more than one cpu? What’s the output of

Get-CimInstance -ClassName win32_Processor

Edit: I changed the code in my original post … try it now.

Ahh, there we go! Thank you so much for the help!! I really appreciate it!

Your welcome.

Now you just have to figure out why your code did not work as expected/planned. :wink: :smiley: