Sometimes I feel the need to do a small inventory.
In this case, the need to do that with monitors found itself to the upper corners of my cranium.
I wanted to get the manufacturer and model. Remembering that many customers also like a serial number in their CMDBs, I put that in there too 🙂
So while waiting for another customer, I wrote this little thing:
1 2 3 4 5 6 7 8 |
$ComputerName = 'MTHSPC01','MTHSPC02','MTHSPC03' Get-CimInstance -Namespace root\wmi -ClassName wmimonitorid -ComputerName $ComputerName | foreach { New-Object -TypeName psobject -Property @{ Manufacturer = ($_.ManufacturerName -notmatch '^0$' | foreach {[char]$_}) -join "" Name = ($_.UserFriendlyName -notmatch '^0$' | foreach {[char]$_}) -join "" Serial = ($_.SerialNumberID -notmatch '^0$' | foreach {[char]$_}) -join "" } } |
Hope you find it useful 🙂
Hello Jeff,
I guess there is small typo in the new-object -typenam instead of -TypeName ?
Regards,
Prashant
Hi Prashant,
You’re correct… changed it 🙂 Thanks!
Jeff
Hey Jeff,
Using the “notmatch 0” comparator gives not the correct result as every character with a 0 in it will be skipped (10,20,30,40,…)
In my case I get this result: ‘DELL U41M’ instead of ‘DELL U2412M’
(where the number 2 is Decimal 50)
This also applies to serial number & manufacturer.
Kind regards,
Tim
in addition of my other reply from yesterday.
I fixed it using -notmatch ‘^0$’
so only a single 0 will be skipped.
Kind regards,
Tim
Hi Tim,
Thanks for commenting, I’ve updated the code accordingly.
Jeff.
Thanks for sharing Jeff, this was exactly what I was looking for!