Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Powershell variable treated as NULL in New-GlobalAddressList cmdlet

Posted on 2014-04-15
5
Medium Priority
?
685 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:Jon Brelie
[X]
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
  • 3
  • 2
5 Comments
 
LVL 16

Author Comment

by:Jon Brelie
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 2000 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:Jon Brelie
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:Jon Brelie
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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
As much as Microsoft wants to kill off PST file support, just as they tried to do with public folders, there are still times when it is useful or downright necessary to export Exchange mailboxes to PST files. Thankfully, it is still possible to e…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

618 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