Link to home
Create AccountLog in
Avatar of motioneye
motioneyeFlag for Singapore

asked on

Powershell error

Hi,
I just got stuck with my powershell script to extract  services logon information.

$Instances = get-content "e:\allservers.txt"

$Instances|%{
$sqlservice = Get-WmiObject      
      -namespace root\Microsoft\SqlServer\ComputerManagement
      -class SqlService
      -filter "ServiceName='MSSQL`$_'"
$sqlService
} >> e:\result.txt


Below is the error msgs


PS E:\> .\services.ps1
Missing expression after unary operator '-'.
At E:\xhpyahyadm\services.ps1:5 char:3
+     - <<<< namespace root\Microsoft\SqlServer\ComputerManagement
    + CategoryInfo          : ParserError: (-:String) [], ParseException
    + FullyQualifiedErrorId : MissingExpressionAfterOperator

PS E:\>
ASKER CERTIFIED SOLUTION
Avatar of Neil Russell
Neil Russell
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of motioneye

ASKER

I tried that but I still got the same error message

Hi,
anyone can help with this problem i had ?
The solution did not help me, anyway thanks for sharing your thought.