Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 87
  • Last Modified:

scripting, exchange

I am running script on ems on my mailbox server to create bulk users in AD , and I am getting this error

anybody can help why is this throwing error
Capture1.JPG
0
pramod1
Asked:
pramod1
  • 24
  • 11
1 Solution
 
Todd NelsonSystems EngineerCommented:
Are you running that command from the Exchange 2007 Management Shell?
0
 
pramod1Author Commented:
yes
0
 
Todd NelsonSystems EngineerCommented:
If you want to run AD-based commands like Get-ADUser and New-ADUser you will need to import the proper toolset into the Exchange 2007 EMS.

Try adding the following to the beginning of your script or before you run the command shown in the screenshot...

Import-Module ActiveDirectory

Open in new window


If this is in reference to your other request (https://www.experts-exchange.com/questions/28970474/exchange-2007-scripts.html?anchor=a41837006#a41837006) it is the same issue.  And I suggest subtle changes to that script so it looks something more like this...

Import-Module ActiveDirectory

$Password = Read-Host "Enter Password:" -AsSecureString

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;

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

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

}

Open in new window


Please try it out before to close your question and award points blindly.
0
Improved Protection from Phishing Attacks

WatchGuard DNSWatch reduces malware infections by detecting and blocking malicious DNS requests, improving your ability to protect employees from phishing attacks. Learn more about our newest service included in Total Security Suite today!

 
pramod1Author Commented:
I am running above  command on dc, but I have 2 questions

in the script attached at top

1) how can I put customized password
and the upn should be domain-hq.com and email address domain-retail.com as far as email address it is incorporating that
do I need to run this first
$Password=Read-Host “Enter Password” –AsSecureString
0
 
Todd NelsonSystems EngineerCommented:
Adding a password cannot be done in clear text and needs to be done in a secure way by issuing the command I provided ($Password = Read-Host "Enter Password:" -AsSecureString) before creating the mailbox/user and piped into the script.  Alternately, you can remove the "-Password" parameter from the New-Mailbox command so the scripts prompts you to enter a password manually for each user as the script runs for every user in the CSV file.

What is the other question?  You stated you have 2.

Are you familiar that UPN stands for user principal name (i.e. jdoe@domain.com) which is not the same as the UPN suffix (i.e. domain.com)?
0
 
pramod1Author Commented:
when I am creating AD account, everything gets created ok but as per attached capture1.jpg, but the upn shows same as user@domain-retail.com  which is the email address of user , I have to manually change the upn domain name that is domain-hq.com

is there any way the script runs where upn is user @domain-hq.com and email remains the same user@domain-retail.com

mport-csv .\BulkAddUsers.csv | foreach { New-ADUser -GivenName $_.GivenName -Surname $_.Surname -Name $_.Name -SamAccountName $_.SamAccountName -Description $_.Description -UserPrincipalName $_.email -Path $_.Path -Enabled $True -AccountPassword (ConvertTo-SecureString $_.Password -AsPlainText -force) -PasswordNeverExpires $True -Email $_.Email}


please find the csv I am running
BulkAddUsers.csv
0
 
Todd NelsonSystems EngineerCommented:
Sure there is a way to do it.  Review the parameter options for New-ADUser ... https://technet.microsoft.com/en-us/library/ee617253.aspx.  Your CSV is close but not there.  If you want the UserPrincipalName parameter set to a different value than what you have set for email address you will need to provide a different value.

HINT: Maybe a new column in the CSV file with a header value of UserPrincipalName and associated values set for each user to ...@domain-hq.com.

But before you can set the UPN you will need to add a UPN suffix for "domain-hq.com" to the forest/domain you are running this script.

References...

0
 
pramod1Author Commented:
I have the upn suffix added,  I have made changes in csv file but where I need to add in the script
BulkAddUsers-test.csv
bulk-ad-script.txt
0
 
Todd NelsonSystems EngineerCommented:
In your script, based on your updated CSV file, all you should need to change is "-UserPrincipalName $_.email" to "-UserPrincipalName $_.UserPrincipalName".
0
 
pramod1Author Commented:
Import-Module ActiveDirectory

$Password = Read-Host "Enter Password:" -AsSecureString

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;

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

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

}


when running above, I am getting this error
Capture.JPG
0
 
Todd NelsonSystems EngineerCommented:
You really need to do better at breaking out your topics.  One is specific for AD and the other is specific for Exchange.

Where are you running this latest script from?

And what does the CSV file look like?
0
 
pramod1Author Commented:
this one is from exchange account
0
 
pramod1Author Commented:
AD part works fine now
0
 
pramod1Author Commented:
EXCHANGE PART ERROR

 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;

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

      Add-DistributionGroupMember -Identity "OWA" -Member $_.upn;
EXCHNAGE-SIDE-ERROR.JPG
0
 
Todd NelsonSystems EngineerCommented:
Don't run the two commands for Add-DistributionGroupMember together.  Make sure they run separately.
0
 
pramod1Author Commented:
I didn't get you, you mean run add distribution group sepeartely
0
 
pramod1Author Commented:
so how it co-relate  with earlier command I ran
0
 
pramod1Author Commented:
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;

till here it works fine
0
 
pramod1Author Commented:
but after that it throws error I attached
0
 
pramod1Author Commented:
can i add Add-DistributionGroupMember -Identity "ActiveSync, storetablet" -Member $_.upn;

like this?
0
 
pramod1Author Commented:
all in one line
0
 
Todd NelsonSystems EngineerCommented:
With the error you provided the, command looks to be running like this...

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

Open in new window


Instead of like this...

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

Open in new window


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

Open in new window


If you copied the script I provided, you need to make sure the closing bracket is there "}".
0
 
pramod1Author Commented:
I am not getting you todd? I run below and when prompt comes should

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;

U MEAN HIT ENTER HERE?

Add-DistributionGroupMember -Identity "ActiveSync" -Member $_.upn;
0
 
pramod1Author Commented:
CAN YOU REMOTE IN
0
 
Todd NelsonSystems EngineerCommented:
This is what the script should look like.  Include the ending bracket ... "}".

Import-Module ActiveDirectory

$Password = Read-Host "Enter Password:" -AsSecureString

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;

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

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

}

Open in new window

0
 
pramod1Author Commented:
can u remote in through team viewer  for a sec
0
 
pramod1Author Commented:
Import-Module ActiveDirectory

$Password = Read-Host "Enter Password:" -AsSecureString

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;

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

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

}
0
 
pramod1Author Commented:
this is what I am putting in shell,
0
 
pramod1Author Commented:
it is not working for distribution groups
0
 
pramod1Author Commented:
do I need to put exactly like yours with numbers
0
 
pramod1Author Commented:
bracket ... "}".
0
 
pramod1Author Commented:
you haven't put it
0
 
pramod1Author Commented:
same error
Capture.JPG
0
 
Todd NelsonSystems EngineerCommented:
private message me
0
 
Todd NelsonSystems EngineerCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

  • 24
  • 11
Tackle projects and never again get stuck behind a technical roadblock.
Join Now