Solved

Powershell variable treated as NULL in New-GlobalAddressList cmdlet

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
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 a Contact 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 Recipients >> Contact ta…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

758 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

20 Experts available now in Live!

Get 1:1 Help Now