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
}
}