# UPDATE-USERCUTOVER.PS1
# Binary Tree Inc
# Sept 2019
# Disclaimer: This example script is shared freely without warranty or support. It is only intended to provide guidance by example to project administrators.
# The script gets users in the complete state from P365 then runs a set mailbox and a set cas mailbox command on the source user mailbox when the cutover is complete.
# The script filters based on migration state to get a list of users.
# The script next verifies the deliver and forward are currently set to true or enabled. If this is true the script proceeds.
# When the script proceeds the set-mailbox command is run to set forwarding only on the mailbox.
# Next the script will run the set-casmailbox command to disable MAPI access to the migrated mailbox.
# This script can be run on a schedule it can also be run using Power DS workflow.
# Don't forget to add your API key to connect to Power365 and your Office 365 admin password if you are running this script unattended.
# This script is featured in this blog. https://www.binarytree.com/blog-portal/blog/2019/september/powershell-for-power365/
#Connect to Exchange Online
$TargetAdminAccount = "O365.Admin@contoso.onmicrosoft.com"
$Targetpasswd = ConvertTo-SecureString "Password1234" -AsPlainText -Force
$TargetCreds = New-Object System.Management.Automation.PSCredential ($TargetAdminAccount, $Targetpasswd)
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $TargetCreds -Authentication Basic –AllowRedirection
Import-PSSession $Session
Import-Module msonline
Connect-MsolService -Credential $TargetCreds
# Connect to production instance of Power365
$apiKey = "Enter Key Here"
Connect-BTSession -ApiKey (ConvertTo-SecureString $apiKey -AsPlainText -Force)
Get-InstalledModule -Name BinaryTree.Power365 | FL
Get-Command -Module BinaryTree.Power365 | select name, ParameterSets
# Get users that have completed cutover
# Verify users currently have deliver and forward enabled
# If they do run these commands
# Enable Forward Only
# Disable MAPI access
# Additional commands could be added here to run against a user, these are only common examples
# Get Power365 Users in the complete state
$COUsers = @()
$COUsers = get-btuser -Filter "MigrationState -eq 'Complete'" | select primarysmtpaddress
foreach ($COUser in $COUsers){
$MBX = Get-mailbox -Identity $COUser.primarysmtpaddress
If ($MBX.DeliverToMailboxAndForward -eq $true)
{
# Display Users
# $name = (($COUser.primarysmtpaddress).ToString())
# write-host "Settting mailbox to only forward and disabling MAPI: $name " -ForegroundColor Yellow
# Set Forwarding Only on Mailbox user
$users_mbx = @()
$users_mbx = Set-mailbox -Identity $COUser.primarysmtpaddress -DeliverToMailboxAndForward $false
# Display Results
# $users_mbx_results = Get-mailbox -Identity $COUser.primarysmtpaddress
# $users_mbx_results |Format-Table Name,PrimarySMTPaddress,DeliverToMailboxAndForward -AutoSize -Wrap
# Set CAS Mailbox MAPI feature to OFF for mailbox user
$users_casmbx = @()
$users_casmbx = Set-casmailbox -Identity $COUser.primarysmtpaddress -MapiEnabled $false
# Display Results
# $users_casmbx_results = Get-casmailbox -Identity $COUser.primarysmtpaddress
# $users_casmbx_results |Format-Table Name,PrimarySmtpAddress,MapiEnabled -AutoSize -Wrap
}
}
© ALL RIGHTS RESERVED. Feedback Terms of Use Privacy Cookie Preference Center