Solved

exchange, scripts

Posted on 2016-10-10
3
91 Views
Last Modified: 2016-10-11
I am trying to run below command  on my exchange resource forest set up

Import-CSV CreateMailboxes-tt.csv | ForEach {

     New-Mailbox -Alias $_.alias -Name $_.name -FirstName $_.Givenname -LastName $_.Surname -userPrincipalName $_.UPN -Database “Field Mailbox Database” -OrganizationalUnit ' Email accounts' -Password $Password -LinkedDomainController "domain..COM" -LinkedMasterAccount "domain\$($_.Name)";

     Get-ADUser -Filter { UserPrincipalName -like $_.upn } | Disable-ADAccount;

SCRIPT RUNS FINE TILL HERE BUT THEN THROWS ERROR (ATTACHED) when adding distribution group

     Add-DistributionGroupMember -Identity "ActiveSync" -Member $_.upn;

     Add-DistributionGroupMember -Identity "OWA" -Member $_.upn;

}

I am running this csv file but I need to add additional email address to my exchange account domain-retail.com which I have to add manually after the user is created in exchange , is there anyw ay I can incorporate this email address domain-retail.com as primary addressERRORcreatemailboxes-tTt.csv
0
Comment
Question by:pramod1
[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
  • 2
3 Comments
 
LVL 16

Expert Comment

by:Todd Nelson
ID: 41837588
Send me a private message in the morning.
0
 
LVL 41

Expert Comment

by:Adam Brown
ID: 41837678
You're trying to use $_.upn in a spot that doesn't pipe that value. Code should work better like this:

$mailboxes = Import-CSV CreateMailboxes-tt.csv 
ForEach ($box in $mailboxes) {
New-Mailbox -Alias $box.alias -Name $box.name -FirstName $box.Givenname -LastName $box.Surname -userPrincipalName $box.UPN -Database “Field Mailbox Database” -OrganizationalUnit ' Email accounts' -Password $Password -LinkedDomainController "domain.COM" -LinkedMasterAccount "domain\$($box.Name)";

Get-ADUser -Filter { UserPrincipalName -like $box.upn } | Disable-ADAccount;

Add-DistributionGroupMember -Identity "ActiveSync" -Member $box.upn;

Add-DistributionGroupMember -Identity "OWA" -Member $box.upn;

}

Open in new window


You can use the pipeline in the new-mailbox cmdlet because that's pulling data from your Import-csv cmdlet. But that attribute is overwritten when you pipe get-aduser to disable-adaccount. As a result, what you're trying to do is too complex to rely on the pipeline attribute $_.

To get around that problem, we can package the import-csv data into an attribute, then run foreach using the ($object in $array) method. This will process the entire CSV array object by creating a $box object for each line in the array, then running the commands in the Foreach scriptblock. With that technique, you can then call $box.upn and get the appropriate value without worrying about a broken pipeline.
0
 
LVL 16

Accepted Solution

by:
Todd Nelson earned 500 total points
ID: 41838783
Pramod,

 Good working with you.  Based on the conversation yesterday, you do not need to provide a password for linked mailboxes because they are created as disabled accounts.  So I've removed those items.  And I added the setting of a custom attribute to set the proper default reply address based on your email address policies.

Import-CSV CreateMailboxes-tt.csv | ForEach {

     New-Mailbox -Alias $_.alias -Name $_.name -FirstName $_.Givenname -LastName $_.Surname -userPrincipalName $_.UPN -Database “Field Mailbox Database” -OrganizationalUnit ' Email accounts' -LinkedDomainController "domain..COM" -LinkedMasterAccount "domain\$($_.Name)"

     Set-Mailbox -Identity $_.alias -CustomAttribute15 "StoreTablets"

     Add-DistributionGroupMember -Identity "ActiveSync" -Member $_.upn

     Add-DistributionGroupMember -Identity "StoreTabletAccts" -Member $_.upn

     Add-DistributionGroupMember -Identity "StoreTablets" -Member $_.upn
}

Open in new window



Good luck with your project.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

635 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