Solved

Powershell variable treated as NULL in New-GlobalAddressList cmdlet

Posted on 2014-04-15
5
644 Views
Last Modified: 2014-04-17
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?
0
Comment
Question by:Enphyniti
  • 3
  • 2
5 Comments
 
LVL 16

Author Comment

by:Enphyniti
ID: 40002653
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?
0
 
LVL 14

Accepted Solution

by:
Justin Yeung earned 500 total points
ID: 40006587
if you do a $test = {CustomAttribute10 -eq $uniqueID}

The variable $test only return as the same
 {CustomAttribute10 -eq $uniqueID}

you can do a variable for the filter like this

$filter = "CustomAttribute10 -eq `"$uniqueID`""

New-GlobalAddressList -Name "$($uniqueID)_GAL" -RecipientFilter $Filter
0
 
LVL 16

Author Comment

by:Enphyniti
ID: 40007020
Magnificent!  You have no idea how many combinations of quotes and backticks I've tried to get this working.  Thank you!
0
 
LVL 16

Author Closing Comment

by:Enphyniti
ID: 40007022
works perfectly!
0
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 40007023
I know I have tried a few times as well.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A brief introduction to what I consider to be the best editor for PowerShell.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now