Exchange Server 2013 Hybrid environment script question

Hello,

I have a script setup to search and apply licenses to my office365 users that are synced.  I also need to run the remote-mailbox command to enable these Office365 users in my on-premise exchange GAL.  In my script when it gets to the enable-remote mailbox portion I get the error the term 'Enable-RemoteMailbox' is not recognized as the name of a cmdlet.  Any ideas?

param 

[Parameter(Position=0, Mandatory = $false, HelpMessage="Creates 'scheduled task' in Windows Scheduler that can be adjusted in the future to perform synchronization cycle(s) at particular time interval")]
[Switch] $Schedule,

[Parameter(Position=1, Mandatory = $false, HelpMessage="Creates text file containing encrypted password")]
[Switch] $Setpassword
)

# Switch to directory where script is located
pushd (split-path -parent $MyInvocation.MyCommand.Definition)

if ($Setpassword)
{
# If password needs to be re-saved, run: "./Autolicense.ps1 -Setpassword" 
$cred = Get-Credential
$cred.Password | ConvertFrom-SecureString | Set-Content c:\o365\password.txt 
exit
}
if ($schedule)
{
# If scheduled tasks needs to be recreated, run: "./Autolicense.ps1 -schedule" 
$taskname = "O365 Auto Licensing Script"
schtasks.exe /create /sc HOURLY /MO 1 /st 06:00 /tn "$taskname" /tr "$PSHOME\powershell.exe -c '. ''$($myinvocation.mycommand.definition)'''"
exit
}

$MsolAdmUser = "email address 
$pwd = Get-Content c:\o365\password.txt | ConvertTo-SecureString 
$cred = New-Object System.Management.Automation.PSCredential $MsolAdmUser, $pwd


# CONNECT TO 365
Import-Module MSOnline
Connect-MsolService -Credential $cred

# RETRIEVE ACCOUNT INFORMATION
$ActSku = "school:StandardWOFFPACK_STUDENT"

# get array of unlicensed users
$users = get-msoluser -UnlicensedUsersOnly 
if (!($users)){write-host -fore Yellow "No unlicensed users";exit}

# VERIFY IF USER IS ALREADY LICENSED

foreach ($user in $users)  
{
    # Write-Host $user.UserPrincipalName
   # SET LOCATION
   Set-MsolUser -UserPrincipalName $user.UserPrincipalName -UsageLocation "US"
   # LICENSE USER
   Set-MsolUserLicense -UserPrincipalName $user.UserPrincipalName AddLicenses "ManhattanTech:STANDARDWOFFPACK_IW_STUDENT"
   Enable-RemoteMailbox -PrimarySMTPAddress ($user.samaccountname+'@m.edu') -RemoteRoutingAddress ($user.samaccountname+'@m.edu.onmicrosoft.com')
   #Set-MsolUserLicense -UserPrincipalName $user.UserPrincipalName AddLicenses $ActSku.AccountSkuId
   $O365UsrResult = Get-MsolUser -UserPrincipalName $user.UserPrincipalName
   if ($O365UsrResult.isLicensed -eq $true)
   #if ($O365UsrResult.isLicensed -eq $false)
   {
     Write-Output $user.UserPrincipalName | Out-File c:\O365\AutoLicenseLog.txt -Append 
   }
 
 }

July 27th, 2015 10:58am

You should run 'Enable-RemoteMailbox' against the on-prem Exchange.
Free Windows Admin Tool Kit Click here and download it now
July 27th, 2015 3:35pm

You should run 'Enable-RemoteMailbox' against the on-prem Exchange.
July 27th, 2015 7:29pm

You should run 'Enable-RemoteMailbox' against the on-prem Exchange.
Free Windows Admin Tool Kit Click here and download it now
July 27th, 2015 7:29pm

Hi,

According to your description, I understand the issue is related to some code or script.

This forum focuses on some general discussion about Exchange .

Additionally, I suggest we can ask a question in Microsoft Exchange Development forum to get more help:

https://social.technet.microsoft.com/Forums/exchange/en-US/home?forum=exchangesvrdevelopment

Thank you for your understanding.

Regards ,

David 


July 27th, 2015 9:21pm

You should run 'Enable-RemoteMailbox' against the on-prem Exchange.

Correct - you do not state which PowerShell host is executing the commands. 

Open a Remote PowerShell session to the on-premises Exchange server 2010 / 2013 server.

And do not directly load the 2010 or 2013 Exchange snap in:

http://blogs.technet.com/b/rmilne/archive/2015/01/28/directly-loading-exchange-2010-or-2013-snapin-is-not-supported.aspx

Free Windows Admin Tool Kit Click here and download it now
July 31st, 2015 12:26am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics