# New to Powershell and am confused.

**URL:** <https://forums.powershell.org/t/new-to-powershell-and-am-confused/7200>\
**Category:** PowerShell Help\
**Created:** [September 16, 2016, 10:48am UTC](https://forums.powershell.org/t/new-to-powershell-and-am-confused/7200 "2016-09-16T10:48:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![larry-gross](https://avatars.discourse-cdn.com/v4/letter/l/d6d6ee/32.png) [@larry-gross](https://forums.powershell.org/u/larry-gross)\
**Post date:** [September 16, 2016, 10:48am UTC](https://forums.powershell.org/t/new-to-powershell-and-am-confused/7200/1 "2016-09-16T10:48:12Z")

</div>

The command below works but with two monitors the second serial number is truncated I do not know why. Now obviously being new I did not write the code below.

```
$monitorserial = gwmi WmiMonitorID -computername $x -Namespace root\wmi | ForEach-Object {($_.UserFriendlyName -notmatch 0 | foreach {[char]$_}) -join ""; ($_.SerialNumberID -notmatch 0 | foreach {[char]$_}) -join ""}
    Write-Host ("Monitor Model(s) and Serial Number(s) is $monitorserial") -ForegroundColor Blue
    Write-Host "`n"
```

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [September 16, 2016, 10:52am UTC](https://forums.powershell.org/t/new-to-powershell-and-am-confused/7200/2 "2016-09-16T10:52:32Z")

</div>

If you just run:

gwmi WmiMonitorID -Namespace root\wmi | fl \*

locally on an HP, is all the information present?

---

<div class="post-metadata">

**Author:** ![larry-gross](https://avatars.discourse-cdn.com/v4/letter/l/d6d6ee/32.png) [@larry-gross](https://forums.powershell.org/u/larry-gross)\
**Post date:** [September 16, 2016, 11:33am UTC](https://forums.powershell.org/t/new-to-powershell-and-am-confused/7200/3 "2016-09-16T11:33:26Z")

</div>

Thank you for the reply. I was doing some further research and found out that if there is only one monitor attached to a system the number comes out correctly. Also I should have been clearer on what I am doing. I was verifying serial numbers on remote systems that I do not have access to but know the system and monitors are on. I verified this on a system with only one hp monitor attached.

---

<div class="post-metadata">

**Author:** ![mike-eyler](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@mike-eyler](https://forums.powershell.org/u/mike-eyler)\
**Post date:** [September 17, 2016, 7:43pm UTC](https://forums.powershell.org/t/new-to-powershell-and-am-confused/7200/4 "2016-09-17T19:43:47Z")

</div>

Try this:

$Workstations = @(‘pc1’,‘pc2’)

foreach ($Workstation in $Workstations)  
{

$SerialNumbers = (Get-WmiObject -Namespace root\wmi -Class WmiMonitorID -ComputerName $Workstation | Where-Object {(($_.UserFriendlyName -and $_.SerialNumberID) -notmatch 0)}).SerialNumberID -join “”  
$Workstation  
$SerialNumbers  
}

I did not test on a dual monitor system. You may need to do further text manipulation(ex, -Split) if it returns two or more serial numbers.

---

<div class="post-metadata">

**Author:** ![erik-sundin](https://avatars.discourse-cdn.com/v4/letter/e/f0a364/32.png) [@erik-sundin](https://forums.powershell.org/u/erik-sundin)\
**Post date:** [September 19, 2016, 1:27am UTC](https://forums.powershell.org/t/new-to-powershell-and-am-confused/7200/5 "2016-09-19T01:27:52Z")

</div>

Just wanted to add that this code is a bit broken, excluding zeros (-notmatch 0) yield some weird results. As an example, on my system the models DELL U2713HM and LA2405 becomes DELL U713HM and LA405 (the code works if I don´t exclude the zeros from .UserFriendlyName).

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:40pm UTC](https://forums.powershell.org/t/new-to-powershell-and-am-confused/7200/6 "2024-05-16T20:40:20Z")

</div>


