Sharing the all in one powershell functions that I use daily for o365 administration, it makes my work easy so want to share if others also want to utilize.

Different o365 services have different connecting  uri & mechanisms, I covered these in one single script that you can load in your powershell profile.

These are the Functions inside the script:

 

Here are the steps to load it:

1. Check if powrshell profile already exists

Use TEST-Path $profile

 if profile exists value will be true else its false.

2. open the profile in notepad - notepad $profile

Add the below code:

$loadscripts="C:\AutoloadScripts"  #place the downloaded script from above in this location
(Get-ChildItem "$loadscripts").FullName | ForEach-Object {Write-Host "Loading Script "$_"" -foregroundcolor green;.$_}

 

 

3. if profile doesn't exists than you can create it by using below command & follow above guideline afterwards

 

new-item -path $profile -itemtype file -force

Now when you launch all powershell scripts inside the autoloadscript location will be loaded & We can use for example:

LaunchEOL to connect to Exchange online:

 

 

Please note that all commands I have prefixed when importing the session so get-mailbox is get-eolmailbox, same has been done for SOL,SHO,COL.

No changes to Azure active directory.

This I have done on purpose as I don;t want to confuse my scripts between online & onpremise commands :)

 

You can use RemoveEOL,RemoveSOL etc to remove the sessions.

 

 

PowerShell
Edit|Remove
<#     
    =========================================================================== 
     Created on:       12/15/2016 1:32 PM 
     Created by:       Vikas Sukhija 
     Organization:      
     Filename:         o365.ps1 
     Update:        08/18/2017 (Updated LaunchSPO/RemoveSPO from SHO) 
     Update:        10/24/2018 (included Exchange Online MFA) 
     ------------------------------------------------------------------------- 
     O365 shells ALL in One 
    =========================================================================== 
#> 
#############################Exchange Online################## 
Function LaunchEOL { 
 
$UserCredential = Get-Credential 
 
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection 
 
Import-PSSession $Session -Prefix "EOL" -AllowClobber 
 
} 
 
 
 
Function RemoveEOL { 
 
$Session = Get-PSSession | where {$_.ComputerName -like "outlook.office365.com"} 
Remove-PSSession $Session 
 
} 
#############################Exchange MFA Online################## 
Function LaunchEOLMFA { 
 
    Import-Module $((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter Microsoft.Exchange.Management.ExoPowershellModule.dll -Recurse ).FullName|?{$_ -notmatch "_none_"}|select -First 1) 
    $EOLSession = New-ExoPSSession  
    Import-PSSession $EOLSession -Prefix "EOL" -AllowClobber -Verbose 
     
    } 
     
    Function RemoveEOLMFA { 
     
    $Session = Get-PSSession | where {$_.ComputerName -like "outlook.office365.com"} 
    Remove-PSSession $Session 
     
    } 
########################Skype Online############################# 
function LaunchSOL 
{ 
    param 
    ( 
        $Domain, 
        $UserCredential 
    ) 
     
    Write-Host "Enter Skype Online Credentials" -ForegroundColor Green 
    $CSSession = New-CsOnlineSession -Credential $UserCredential -OverrideAdminDomain $Domain -Verbose 
    Import-pssession $CSSession -Prefix "SOL" -AllowClobber 
} 
 
Function RemoveSOL 
{ 
     
    $Session = Get-PSSession | where { $_.ComputerName -like "admin1a.online.lync.com" } 
    Remove-PSSession $Session     
} 
 
#####################Sharepoint Online############################### 
 
function LaunchSPO 
{ 
    param 
    ( 
        $orgName 
    ) 
     
    Write-Host "Enter Sharepoint Online Credentials" -ForegroundColor Green 
    $userCredential = Get-Credential 
    Connect-SPOService -Url https://$orgName-admin.sharepoint.com -Credential $userCredential 
} 
 
Function RemoveSPO 
{ 
     
    disconnect-sposervice 
} 
 
#########################Secuirty and Compliance########################## 
 
Function LaunchCOL { 
 
$UserCredential = Get-Credential 
 
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection 
 
Import-PSSession $Session -Prefix "COL" -AllowClobber 
 
} 
 
 
 
Function RemoveCOL { 
 
$Session = Get-PSSession | where {$_.ComputerName -like "*compliance.protection.outlook.com"} 
Remove-PSSession $Session 
 
} 
#############################Compliance Online################## 
Function LaunchCOLMFA { 
 
    Import-Module $((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter Microsoft.Exchange.Management.ExoPowershellModule.dll -Recurse ).FullName|?{$_ -notmatch "_none_"}|select -First 1) 
    $COLSession = New-EXOPSSession -ConnectionUri 'https://ps.compliance.protection.outlook.com/PowerShell-LiveId' 
    Import-PSSession $COLSession -Prefix "COL" -AllowClobber -Verbose 
     
    } 
     
    Function RemoveCOLMFA { 
     
    $Session = Get-PSSession | where {$_.ComputerName -like "*compliance.protection.outlook.com"} 
    Remove-PSSession $Session 
     
    } 
###############################Msonline######################### 
function LaunchMSOL 
{ 
    import-module msonline 
    Write-Host "Enter MS Online Credentials" -ForegroundColor Green 
    Connect-MsolService 
} 
 
Function RemoveMSOL 
{ 
     
    Write-host "Close Powershell Window - No disconnect available" -ForegroundColor yellow 
} 
##################################################################
 

 

Regards

Sukhija Vikas

http://msexchange.me