Link to home
Start Free TrialLog in
Avatar of Alex
AlexFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Syntax error Powershell (easy question

Morning

It's Monday and I'm screwing up

get-adcomputer -Filter {(name -Like "*TP*" or "*TQ*" or "*TS*")} -SearchBase $OU | Select Name | Out-File 'C:\Powershell Projects\TillSC\Computers.txt'

Open in new window


and I get this

get-adcomputer : Error parsing query: '(name -Like "*TP*" or "*TQ*" or "*TS*")' Error Message: 'syntax error' at position: '20'.
At line:3 char:1
+ get-adcomputer -Filter {(name -Like "*TP*" or "*TQ*" or "*TS*")} -Sea ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ParserError: (:) [Get-ADComputer], ADFilterParsingException
    + FullyQualifiedErrorId : Error parsing query: '(name -Like "*TP*" or "*TQ*" or "*TS*")' Error Message: 'syntax error' at position: '20'.,Microsoft.Acti
   veDirectory.Management.Commands.GetADComputer
 
Any ideas?

Thanks

Alex
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
get-adcomputer -Filter {(name -Like "*TP*" -or  name -like "*TQ*" -or name -like "*TS*")} -SearchBase $OU | Select Name | Out-File 'C:\Powershell Projects\TillSC\Computers.txt'
Avatar of Alex

ASKER

GRRRR!!!!!!!

Thanks chris, I didn't realise I needed the Name function again in there, I thought I could just use the Or...

Thanks again..

Alex