D
D
Dmitry Shumov2019-12-26 11:59:12
PowerShell
Dmitry Shumov, 2019-12-26 11:59:12

Get-WmiObject why does not work correctly?

There is a script:

$computers = Get-Content -Path C:\temp\foo.csv
Get-WmiObject -ComputerName $computers -Class Win32_UserAccount -Filter "LocalAccount=True" | Select PSComputername, Name, Status, Disabled, AccountType, Lockout, PasswordRequired, PasswordChangeable | Out-GridView

When you try to execute it, it throws out a bunch of errors (depending on the number of lines in foo.csv):
Get-WmiObject : Сервер RPC недоступен.
строка:2 знак:1
+ Get-WmiObject -ComputerName $computers -Class Win32_UserAccount -Filt ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

However, if you just run the command:
Get-WmiObject -ComputerName <b>PSname</b> -Class Win32_UserAccount -Filter "LocalAccount=True" | Select PSComputername, Name, Status, Disabled, AccountType, Lockout, PasswordRequired, PasswordChangeable | Out-GridView

she works great. Why is that?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Shumov, 2019-12-26
@dshumov

I don’t know what specifically helped, but I did the following:
1) Registered FQDN server names
2) Removed empty lines (on the list and 2000 entries, for some reason there were about 5 empty lines)

A
Alexey Dmitriev, 2019-12-26
@SignFinder

Get-WmiObject in ForEach should be when there is an array of data in the variable

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question