Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Powershell variable treated as NULL in New-GlobalAddressList cmdlet

Posted on 2014-04-15
5
650 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

Lotus Notes – formerly IBM Notes – is an email client application, while IBM Domino (earlier Lotus Domino) is an email server. The client possesses a set of features that are even more advanced as compared to that of Outlook. Likewise, IBM Domino is…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this video we show how to create an Address List in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Organization >> Ad…
To show how to generate a certificate request in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Servers >> Certificates…

840 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