WurthAdmin
asked on
Powershell Get-AdObejct with -filter option containing variable
Hi,
When i execute this powershell command line i have some result :
Get-ADObject -Properties mail, proxyAddresses -Filter {mail -like "*pierre.w*" -or proxyAddresses -like "*pierre.w*"} |ft
but when i execute those lines i've got a error :
$emailportion="pierre.w"
$filtre="{mail -like ""*$emailportion*"" -or proxyAddresses -like ""*$emailportion*""}"
Get-ADObject -Properties mail, proxyAddresses -Filter $filtre
Get-ADObject : Error parsing query: '{mail -like "*pierre.w*" -or proxyAddresses -like "*pierre.w*"}' Error Message: 'syntax error' at position: '1'.
At line:1 char:1
+ Get-ADObject -Properties mail, proxyAddresses -Filter $filtre
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~
+ CategoryInfo : ParserError: (:) [Get-ADObject], ADFilterParsingException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Micr osoft.Acti veDirector y.Manageme nt.ADFilte rParsingEx ception,Mi crosoft.Ac tiveDirect ory.Manage ment.Comma nds.GetADO bject
The variable $filtre contain : {mail -like "*pierre.w*" -or proxyAddresses -like "*pierre.w*"}
The help on get-ADObject show the -filter option as a string
SYNTAX
Get-ADObject [-AuthType {Negotiate | Basic}] [-Credential <PSCredential>] [-IncludeDeletedObjects] [-Properties <String[]>] [-ResultPageSize <Int32>] [-ResultSetSize <Int32>] [-SearchBase <String>]
[-SearchScope {Base | OneLevel | Subtree}] [-Server <String>] -Filter <String> [<CommonParameters>]
When i execute this powershell command line i have some result :
Get-ADObject -Properties mail, proxyAddresses -Filter {mail -like "*pierre.w*" -or proxyAddresses -like "*pierre.w*"} |ft
but when i execute those lines i've got a error :
$emailportion="pierre.w"
$filtre="{mail -like ""*$emailportion*"" -or proxyAddresses -like ""*$emailportion*""}"
Get-ADObject -Properties mail, proxyAddresses -Filter $filtre
Get-ADObject : Error parsing query: '{mail -like "*pierre.w*" -or proxyAddresses -like "*pierre.w*"}' Error Message: 'syntax error' at position: '1'.
At line:1 char:1
+ Get-ADObject -Properties mail, proxyAddresses -Filter $filtre
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ParserError: (:) [Get-ADObject], ADFilterParsingException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Micr
The variable $filtre contain : {mail -like "*pierre.w*" -or proxyAddresses -like "*pierre.w*"}
The help on get-ADObject show the -filter option as a string
SYNTAX
Get-ADObject [-AuthType {Negotiate | Basic}] [-Credential <PSCredential>] [-IncludeDeletedObjects] [-Properties <String[]>] [-ResultPageSize <Int32>] [-ResultSetSize <Int32>] [-SearchBase <String>]
[-SearchScope {Base | OneLevel | Subtree}] [-Server <String>] -Filter <String> [<CommonParameters>]
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Best Regard
JP