Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Get-WMiObject w/Query fails from the command prompt

$
0
0

Hi,

I'm a newbie to powershell and I'm trying to get the user name for an installed service.  When I execute the Get-WmiObject command from powershell everything works.  However I need to execute it from a command prompt (calling it from Java).  When I do that, the command fails.

Here is the command (substitute a real service name for MyService):

Powershell.exe -ExecutionPolicy ByPass Invoke-Command -ScriptBlock { Get-WmiObject -Query "select startname from win32_service where name='MyService'" }

I get the following error:

Get-WmiObject : A positional parameter cannot be found that accepts argument 'startname'.

I don't understand why this fails.  I've tried placing " around the Get-WmiObject command.  -Query is not a positional parameter and the query is in ".  I'm not sure what's wrong.

Thanks,

-Mike


Viewing all articles
Browse latest Browse all 6937

Trending Articles