Good Day,
i have included script below, i removed company details. but script was entirely doing below after migration of mailboxes to the cloud.
If there's a script that can do all below with Admin account that has MFA will gladly welcome assistance.
On PowerShell
Step 1 : Change directory to where the script is located
Step 2: Import-csv .\PostMove.csv | .\licence-mailboxuser.ps1
SCRIPT BELOW
param (
[parameter(
valueFromPipeLineByPropertyName=$true,
mandatory=$true
)] $UserPrincipalName
)
begin {
Import-Module MSOnline
Import-Module ActiveDirectory
function login-365 {
if ( -not ( Get-PSSession -Name "365ScriptSession" -erroraction silentlycontinue ) ) {
$LiveCred=$Host.ui.PromptForCredential("Office 365 Login Prompt","Enter your office 365 account details:","","@investec.co.za")
$Session = New-PSSession -Name "365ScriptSession" -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell-liveid?DelegatedOrg=investeceu.onmicrosoft.com -Credential $LiveCred
-Authentication Basic -AllowRedirection -WarningAction silentlyContinue
Import-PSSession $Session -AllowClobber -WarningAction silentlyContinue -Prefix 365 | out-null
connect-MSOLService -Credential $LiveCred
}
}
function login-local {
if ( -not ( Get-PSSession -name "LocalScriptSession" -erroraction silentlycontinue ) ) {
$session=New-PSSession -name "LocalScriptSession" -ConfigurationName Microsoft.Exchange -ConnectionUri "http://EXCHANGESERVER/powershell/" -Authentication Kerberos
Import-PSSession $Session -AllowClobber -prefix OnPrem | out-null
}
}
function Licence-365User {
param (
$UserPrincipalName
)
$AccountSkuId = "COMPANY:ENTERPRISEPACK"
$O365Licenses = New-MsolLicenseOptions -AccountSkuId $AccountSkuId -DisabledPlans "MCOSTANDARD"
$UsageLocation = "COUNTRY"
Set-MsolUser -UserPrincipalName $UserPrincipalName -UsageLocation $UsageLocation
Set-MsolUserLicense -UserPrincipalName $UserPrincipalName -AddLicenses $AccountSkuId -LicenseOptions $O365Licenses
}
function Set-PFProxyAndPolicy {
param (
$UserPrincipalName
)
$Policy = "Retention Policy - 4 years"
$PFProxy = "PFMailbox"
Set-365Mailbox -Identity $UserPrincipalName -DefaultPublicFolderMailbox $PFProxy -RetentionPolicy $policy
}
function Set-Archive {
param (
$UserPrincipalName
)
Enable-OnPremRemoteMailbox $UserPrincipalName -Archive
}
login-local
login-365
}
process {
$mailbox = get-365mailbox -identity $UserPrincipalName
if ( $mailbox ) {
Licence-365User -UserPrincipalName $UserPrincipalName
Set-PFProxyAndPolicy -UserPrincipalName $UserPrincipalName
Set-Archive -UserPrincipalName $UserPrincipalName
}
}