Powershell Script – Asset Inventory – Computer and Monitor Serial Number collection

by Oct 22, 2017

Hi All,

I have got the below script working, though cant figure out how to get it to scan for additional monitors. 

Eg. some of the computers in the office have 4 screens, though i only have a laptop at home to test.

Any one able to show me how to get it to add the details of the additional monitors please?

Thanks

 

 

$ArrComputers = gc C:scriptsMachineList.txt $OutputLog = "C:scriptsMachine_MainLog.txt" # Main log $NotRespondingLog = "C:scriptsMachine_NoResponse_Log.txt" # Logging "unqueried" hosts $ErrorActionPreference = "Stop" # Or add '-EA Stop' to Get-WmiObject queries Clear-Host ForEach ($Computer in $ArrComputers) { try { $computerSystem = get-wmiobject Win32_ComputerSystem -Computer $Computer $computerBIOS = get-wmiobject Win32_BIOS -Computer $Computer $LoggedOnUser = $ComputerSystem.UserName $Version = Get-WmiObject -Namespace "RootCIMv2" ` -Query "Select * from Win32_ComputerSystemProduct" ` -computer $computer | select -ExpandProperty version $MonitorInfo = gwmi WmiMonitorID -Namespace rootwmi ` -computername $Computer ` | Select PSComputerName, ` @{n="Model";e={[System.Text.Encoding]::ASCII.GetString(` $_.UserFriendlyName -ne 00)}}, @{n="Serial Number";e={[System.Text.Encoding]::ASCII.GetString(` $_.SerialNumberID -ne 00)}} } catch { $Computer | Out-File -FilePath $NotRespondingLog -Append -Encoding UTF8 continue } $Header = "System Information for: {0}" -f $computerSystem.Name # Outputting and logging header. write-host $Header -BackgroundColor DarkCyan $Header | Out-File -FilePath $OutputLog -Append -Encoding UTF8 $Output = (@" ——————————————————- Model : {0} User : {1} Serial Number : {2} Version : {3} Monitor Model : {4} Monitor Serial : {5} ——————————————————- "@) -f $computerSystem.Model,$LoggedOnUser, $computerBIOS.SerialNumber, $Version, ` $MonitorInfo.Model, $MonitorInfo."Serial Number" # Ouputting and logging WMI data Write-Host $Output $output | Out-File -FilePath $OutputLog -Append -Encoding UTF8 }