Link to home
Start Free TrialLog in
Avatar of Fr. Vandecan
Fr. VandecanFlag for Belgium

asked on

Combine a variable and a * into a filter

Include Variable AND a "*"  into a query.

for ex :
$MailboxAlias = "DCH"
$ArrMailbox = @(Get-Mailbox -RecipientTypeDetails SharedMailbox -filter 'samaccountname -like "DCH*"' --> $ArrMailbox = @(Get-Mailbox -RecipientTypeDetails SharedMailbox -filter 'samaccountname -like "$Mailboxalias*"'

How to achieve this cause -like "$Mailboxalias*"' does not do  -like "DCH*"' ?
Avatar of David Sankovsky
David Sankovsky
Flag of Israel image

Do it simpler, add the Astrix to the Alias variable..
$MailboxAlias = "DCH*"
$ArrMailbox = @(Get-Mailbox -RecipientTypeDetails SharedMailbox -filter 'samaccountname -like "DCH*"' --> $ArrMailbox = @(Get-Mailbox -RecipientTypeDetails SharedMailbox -filter 'samaccountname -like "$Mailboxalias"'

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America 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
Whether you have the asterisk defined as part of the variable or not, the outer quotes must be double-quotes for the variable to be evaluated inside the filter string.