Solved

Powershell variable treated as NULL in New-GlobalAddressList cmdlet

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

Why won’t your email signature format correctly?

Struggling to get your corporate email signatures to format correctly? Does the logo keep resizing? Is the text appearing too big? What can you do to prevent this? Find out how you can save your signatures today.

Question has a verified solution.

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

This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…
This video discusses moving either the default database or any database to a new volume.

867 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

13 Experts available now in Live!

Get 1:1 Help Now