• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 68
  • Last Modified:

PS Script to have Argument for SamAccount Name in Exchange 2013 Hybrid-Office 365 enviroment

So we have a Hybrid environment with Office 365.  All mailboxes are in the cloud but we have mail routed through our Hybrid on premise server.  Were trying to use the ADManage tool as a 3rd part to create Domain user and have it create mailboxes at the same time.  We need to write a script that takes the below command that we normally run VIA the 2013 EMC on Exchange Hybrid server and have it have an argument for the SamAccount name to be placed in the beginning quotations.  If we can have the "Argument" successfully implemented into a power shell scritp then ADmanage support tells us when we sue their product to create a new user when we get to the 365 portion of their tool this script should run the powershell cmd and create a remote routing address as well as Office 365 account successfully.


""|foreach {Enable-RemoteMailbox -identity $_ -RemoteRoutingAddress "$_@agilysyscorp.mail
.onmicrosoft.com"}
0
Twhite0909
Asked:
Twhite0909
  • 2
1 Solution
 
footechCommented:
What's the source of the samaccountname?  A file that contains a bunch, a .CSV with lots of other info, or typed directly into a console one at a time?

For a plain text file, typically you would have something like
Get-Content yourfile.txt | foreach {Enable-RemoteMailbox -identity $_ -RemoteRoutingAddress "$_@agilysyscorp.mail.onmicrosoft.com"}

Open in new window

0
 
Twhite0909Author Commented:
Active Directory should be the source for the sam account.  I need this script to run for creating a new user is created in our domain.  This script will help the email on 365 get created automatically assuming the user account has already been created the SAMAccount should be pulled from AD.
0
 
footechCommented:
SamAccountNames can be pulled from AD with a command like
Import-Module ActiveDirectory
Get-ADUser -filter * -searchbase "OU-someOU,DC=domain,DC=com" | Select -expandProperty samAccountName

Open in new window

You can pipe that into the ForEach command.  I have included the -searchbase parameter to limit the search to a specific OU and child OUs.  Of course it would have to be run on a system that has the ActiveDirectory module.
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

How do you know if your security is working?

Protecting your business doesn’t have to mean sifting through endless alerts and notifications. With WatchGuard Total Security Suite, you can feel confident that your business is secure, meaning you can get back to the things that have been sitting on your to-do list.

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