Hi to all
Does anyone know any way to get Serial Number monitor using SCCM CB?
any details would be great
Manuel
Here is a script that works fine, input is a text file with all computers you need, hostname one per line save it in the same PowerShell script path. run using account that has administrator privileges on target computers.
save the script as ComputerInfo.ps1 and the text file as MachineList.txt
output is an amazing Excel file
Machine Name | IP Address | Machine Type | Serial Number | Logged On | Monitor 1 Brand | Monitor 1 Model | Monitor 1 Serial Number | Monitor 2 Brand | Monitor 2 Model | Monitor 2 Serial Number | Monitor 3 Brand | Monitor 3 Model | Monitor 3 Serial Number |
Script:
$ErrorActionPreference = "SilentlyContinue"
# Get the current script path
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
# Read the list of computers from a text file
$computers = Get-Content -Path "$scriptPath\MachineList.txt"
# Create a new Excel workbook
$excel = New-Object -ComObject Excel.Application
$workbook = $excel.Workbooks.Add()
$worksheet = $workbook.Worksheets.Item(1)
# Set column headers
$worksheet.Cells.Item(1, 1) = "Machine Name"
$worksheet.Cells.Item(1, 2) = "IP Address"
$worksheet.Cells.Item(1, 3) = "Machine Type"
$worksheet.Cells.Item(1, 4) = "Serial Number"
$worksheet.Cells.Item(1, 5) = "Logged On"
$worksheet.Cells.Item(1, 6) = "Monitor 1 Brand"
$worksheet.Cells.Item(1, 7) = "Monitor 1 Model"
$worksheet.Cells.Item(1, 8) = "Monitor 1 Serial Number"
$worksheet.Cells.Item(1, 9) = "Monitor 2 Brand"
$worksheet.Cells.Item(1, 10) = "Monitor 2 Model"
$worksheet.Cells.Item(1, 11) = "Monitor 2 Serial Number"
$worksheet.Cells.Item(1, 12) = "Monitor 3 Brand"
$worksheet.Cells.Item(1, 13) = "Monitor 3 Model"
$worksheet.Cells.Item(1, 14) = "Monitor 3 Serial Number"
$row = 2
foreach ($computer in $computers) {
# Ping the computer to check if it's online
if (Test-Connection -ComputerName $computer -Count 1 -Quiet) {
$pingResults = $true
# Get IP address
$ipAddress = (Test-Connection -ComputerName $computer -Count 1).IPV4Address.IPAddressToString
# Get WMI objects for the computer
$computerSystem = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $computer
$bios = Get-WmiObject -Class Win32_BIOS -ComputerName $computer
# Get computer details
$machineName = $computerSystem.Name
$machineType = $computerSystem.Model
$serialNumber = $bios.SerialNumber
$loggedInUser = $computerSystem.UserName
# Write computer details to Excel
$worksheet.Cells.Item($row, 1) = $machineName
$worksheet.Cells.Item($row, 2) = $ipAddress
$worksheet.Cells.Item($row, 3) = $machineType
$worksheet.Cells.Item($row, 4) = $serialNumber
$worksheet.Cells.Item($row, 5) = $loggedInUser
# Get monitor information using WMI
$monitors = Get-WmiObject -Namespace root\wmi -Query "SELECT * FROM WmiMonitorID" -ComputerName $computer
$monitorCount = $monitors.Count
for ($i = 0; $i -lt $monitorCount; $i++) {
$monitor = $monitors[$i]
$brand = ([System.Text.Encoding]::ASCII.GetString($monitor.ManufacturerName)).TrimEnd()
$model = ([System.Text.Encoding]::ASCII.GetString($monitor.UserFriendlyName)).TrimEnd()
$serial = ([System.Text.Encoding]::ASCII.GetString($monitor.SerialNumberID)).TrimEnd()
# Write monitor details to Excel
$worksheet.Cells.Item($row, 6 + ($i * 3)) = $brand
$worksheet.Cells.Item($row, 7 + ($i * 3)) = $model
$worksheet.Cells.Item($row, 8 + ($i * 3)) = $serial
}
}
else {
$pingResults = $false
}
if (-not $pingResults) {
$worksheet.Cells.Item($row, 1) = $computer
$worksheet.Cells.Item($row, 2) = "Offline"
}
$row++
}
# Generate the timestamp for the file name
$timestamp = Get-Date -Format "MM-dd-yyyy-HH-mm"
# Save the Excel workbook with the timestamp in the file name
$excelFilePath = "$scriptPath\ComputerInventory_$timestamp.xlsx"
$workbook.SaveAs($excelFilePath)
# Close Excel
$workbook.Close()
$excel.Quit()
# Output the path of the saved Excel file
$excelFilePath