Link to home
Start Free TrialLog in
Avatar of Jon Brelie
Jon BrelieFlag for United States of America

asked on

Powershell variable treated as NULL in New-GlobalAddressList cmdlet

I can't wrap my head around what's going on here.
This works from the powershell commandline:
New-GlobalAddressList -name ThisGuy_GAL -recipientFilter {CustomAttribute10 -eq ThisGuy}

Open in new window

Get-globalAddressList Thisguy_GAL returns the expected recipient filter that looks like this:
CustomAttribute10 -eq 'ThisGuy'


However, if I do the exact same thing in a script, I get a malformed recipient filter
$uniqueID = "ThatGuy"
New-GlobalAddressList -Name "$($uniqueID)_GAL" -RecipientFilter {CustomAttribute10 -eq $uniqueID}

Open in new window


The above executes with no errors, BUT - Get-GlobalAddressList ThatGuy_GAL returns a recipient filter that looks like this:

-not(CustomAttribute10 -ne $null)

What?
Avatar of Jon Brelie
Jon Brelie
Flag of United States of America image

ASKER

If I'm reading this right, then my "$uniqueID" is getting read as a NULL value, thus creating the " Not CustomAttribute10 is not equal to NULL" recipient filter.

Okay, that makes sense.  But why is that value being interpreted as NULL in the recipient filter and not in the name?  I've tried numerous forms of syntax... can anyone provide me with the correct version?
ASKER CERTIFIED SOLUTION
Avatar of Justin Yeung
Justin Yeung
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
Magnificent!  You have no idea how many combinations of quotes and backticks I've tried to get this working.  Thank you!
works perfectly!
I know I have tried a few times as well.