All in One Office 365 Powershell Connect

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:

  • LaunchEOL/RemoveEOL    (Exchange Online)
  • LaunchSOL/RemoveSOL    (Skype online)
  • LaunchSHO/RemoveSHO   (Sharepoint online)
  • LaunchCOL/RemoveCOL    (Security & Compliance)
  • LaunchMSOL/RemoveMSOL (MSonline Azure activedirectory)

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;.$_}

capture

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:

capture

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.

Download linke:

https://gallery.technet.microsoft.com/scriptcenter/All-in-One-Office-365-77005e37

<#     
    =========================================================================== 
     Created on:       12/15/2016 1:32 PM 
     Created by:       Vikas Sukhija 
     Organization:      
     Filename:         o365.ps1 
     ------------------------------------------------------------------------- 
     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 
 
} 
 
########################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 LaunchSHO 
{ 
    param 
    ( 
        $orgName 
    ) 
     
    Write-Host "Enter Sharepoint Online Credentials" -ForegroundColor Green 
    $userCredential = Get-Credential 
    Connect-SPOService -Url https://$orgName-admin.sharepoint.com -Credential $userCredential 
} 
 
Function RemoveSHO 
{ 
     
    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 
 
} 
 
###############################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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s