Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Powershell Script for creating Exchange 2013 Address books I have bad syntax

Posted on 2014-10-22
6
Medium Priority
?
78 Views
Last Modified: 2015-06-18
Hey Gurus I have a simple script i am trying to create via powershell to create some address books in exchange it seems that my variables are not getting passed through:

here is it:
$ssdomainname="Costco Adb"
$ssdomain="costco.com"

"New-AddressList -Name '$ssgroupname' -RecipientFilter {((Alias -ne $null) -and (UserPrincipalName -like '*@$ssdomain'))}"


the acctual command should be : New-AddressList -Name 'Costco Adb' -RecipientFilter {((Alias -ne $null) -and (UserPrincipalName -like '*@costco.com'))}

but the output is :
Name                      DisplayName               RecipientFilter
----                      -----------               ---------------
"$ssgroupname"            "$ssgroupname"            ((Alias -ne $null) -and (UserPrincipalName -like '*@"$ssdomain"'))

the variables are not passing to the commad?

what is the correct syntax?

Thanks Guys!
0
Comment
Question by:sanehpal
  • 2
6 Comments
 
LVL 31

Expert Comment

by:Gareth Gudger
ID: 40398527
What happens if you drop the quotation marks from -Name

So...

"New-AddressList -Name $ssgroupname -RecipientFilter {((Alias -ne $null) -and (UserPrincipalName -like *@$ssdomain))}"
0
 

Author Comment

by:sanehpal
ID: 40398607
i get a At line:1 char:70
+ "New-AddressList -Name '$ssgroupname' -RecipientFilter {((Alias -ne "$null") -an ...
+                                                                      ~~~~~~~~~~~
Unexpected token '$null") -and (UserPrincipalName -like '*@$ssdomain'))}"' in expression or statement.
At line:1 char:75
+ "New-AddressList -Name '$ssgroupname' -RecipientFilter {((Alias -ne "$null") -an ...
+                                                                           ~~~~~~
Unexpected token '") -and (UserPrincipalName -like '*@$ssdomain'))}"' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40837542
I've requested that this question be deleted for the following reason:

The question has either no comments or not enough useful information to be called an "answer".
0
 

Accepted Solution

by:
sanehpal earned 0 total points
ID: 40837461
Figured it out here is the solution:

Step 1: New-AddressList -Name 'Softaire' -RecipientFilter {((Alias -ne $null) -and (UserPrincipalName -like '*@constco.net'))}

Creates new address list with all users in constco.net


Step 2: New-GlobalAddressList -Name "constcoDomain" -RecipientFilter {((Alias -ne $null) -and (UserPrincipalName -like '*@constco.net'))}

New-OfflineAddressBook -Name "constco-All-OAB" -AddressLists "\constco"

\constco is from New-AddressList created in step 1

Step 3: New-AddressBookPolicy -Name "constcoDomain ABP" -AddressLists "\constco" -OfflineAddressBook \constco-All-OAB -GlobalAddressList "\constcoDomain" -RoomList "\constco"

This combines all the created lists to create a policy
0

Featured Post

Ready for your healthcare security check-up?

In the past few years, healthcare organizations have become a prime target for advanced attacks. Does your organization have what it needs to defend itself? Schedule your healthcare security check-up today and download our free Healthcare Security Resource Kit today!

Question has a verified solution.

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

Steps to fix “Unable to mount database. (hr=0x80004005, ec=1108)”.
Stellar Exchange Toolkit: this 5 in 1 toolkit comes loaded with mega-software tool. Here’s an introduction to tools’ usage and advantages:
In this video we show how to create an email address policy 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 Mail Flow…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

916 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