0
votes

I getting the following error:

gwmi : Invalid class "WmiMonitorID"
At line:1 char:1
+ gwmi WmiMonitorID -Namespace root\wmi | ForEach-Object {($_.UserFrie ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     + CategoryInfo          : InvalidType: (:) [Get-WmiObject], ManagementException
     + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

while trying to grab my monitor's Serial ID using:

gwmi WmiMonitorID -Namespace root\wmi | ForEach-Object {
    ($_.UserFriendlyName -notmatch 0 | foreach {[char]$_}) -join "";
    ($_.SerialNumberID -notmatch 0 | foreach {[char]$_}) -join ""
}

I used this command about 2 months back and it worked flawlessly. (Was not even running PowerShell in admin)

code screenshot

Now with or without admin I get the error mentioned above. (also tried x64 and x86 both with/without admin)

error screenshot

Am I overlooking something?

1
May be your WMI is corrupt .Try these steps virtuallyboring.com/…TheGameiswar
@TheGameiswar My WMI Control (Local) looks like the good one in the screenshotnewcool
The second screenshot looks as if there is an additional space in the class. You can see it in Invalid Class " WmiMonitorID" so it might be reading the whitespace.Drew
@Drew Looks like you are right, but now there is a new error. i.imgur.com/jsRYonB.pngnewcool
Now it looks like it is running each line independently instead of it being one larger expression.Drew

1 Answers

0
votes

Thank you very much @Drew for pointing out the whitespace.

So it seems like whatever I was c&p the code from was adding extra spaces to the code which would make it end up looking like

gwmi(Space)(Space)WmiMonitorID(Space)(Space)-Namespace

or add extra spaces at the end

... -join ""}(Space)(Space)

The solution would be to copy it in a .txt or paste bin and make sure the extra spaces are not there before copying back to PowerShell.