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} |