Skip to content

Instantly share code, notes, and snippets.

@JustinGrote
Last active November 27, 2015 00:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JustinGrote/4f70056c013fe9efc3ef to your computer and use it in GitHub Desktop.
Save JustinGrote/4f70056c013fe9efc3ef to your computer and use it in GitHub Desktop.
Adds a submenu and keyboard shortcuts to Powershell ISE for quickly connecting to Office 365 services including on-premises Exchange and importing the commands into your current session.
<#
HOW TO INSTALL
Open your Powershell ISE Profile (when in the ISE type psedit $profile) and either paste this content into it and save, or dot source the file wherever you saved it.
Use Get-Help about_Scripts for more info on dot sourcing
#>
#Microsoft O365 Menu Items
New-Variable -name O365ISECREDENTIAL -scope Script
$connectMenu = $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add("Import Commands From:",$null,$null)
$connectMenu.SubMenus.Add( "Azure (Resource Manager)", {
if (!$O365ISECREDENTIAL) {$O365ISECREDENTIAL = (get-credential)}
Import-Module azurerm.profile -ErrorAction stop
Login-AzureRmAccount -credential $O365ISECREDENTIAL
},
"Control+Alt+A"
)
$connectMenu.SubMenus.Add(
"Exchange Online", {
if (!$O365ISECREDENTIAL) {$O365ISECREDENTIAL = (get-credential)}
$o365ExchSession= New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $O365ISECREDENTIAL -Authentication Basic -AllowRedirection -ErrorAction stop
if (get-command -listimported get-mailbox -erroraction silentlycontinue) {
write-warning "Exchange commands were already found. To avoid conflicts, session commands are prefixed with exo (for Exchange Online) such as Get-exoMailbox, Get-exoOrganizationConfig, etc."
Import-PSSession $o365ExchSession -DisableNameChecking -ErrorAction stop -Prefix exo
} else {
Import-PSSession $o365ExchSession -DisableNameChecking -ErrorAction stop -Verbose
}
},
"Control+Alt+X"
)
$connectMenu.SubMenus.Add(
"Office 365 Compliance Center (CC)", {
if (!$O365ISECREDENTIAL) {$O365ISECREDENTIAL = (get-credential)}
$o365CCSession= New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $O365ISECREDENTIAL -Authentication Basic -AllowRedirection -ErrorAction stop
Import-PSSession $o365CCSession -DisableNameChecking -ErrorAction stop -Prefix cc
write-verbose "To avoid conflicts with Exchange Online, session commands are prefixed with cc (for Compalince Center) such as Get-ccDevicePolicy, New-ccRoleGroup, etc."
},
"Control+Alt+C"
)
$connectMenu.SubMenus.Add(
"Office 365", {
if (!$O365ISECREDENTIAL) {$O365ISECREDENTIAL = (get-credential)}
Import-Module MsOnline -erroraction stop
Connect-MsolService -Credential $O365ISECREDENTIAL -erroraction stop
},
"Control+Alt+O"
)
$connectMenu.SubMenus.Add( "On-Premise Exchange Server", {
$ExchangeHost = Read-Host "Exchange Server Name"
$VerbosePreference = "Continue"
$OnPremExchSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://$ExchangeHost/PowerShell/ -Verbose -AllowRedirection -Authentication Basic -Credential (get-credential -message "Enter the server Exchange Credentials")
$VerbosePreference = "SilentlyContinue"
if (get-command -listimported get-mailbox -erroraction silentlycontinue) {
write-warning "Exchange commands were already found. To avoid conflicts, session commands are prefixed with op (for On-Prem) such as Get-opMailbox, Get-opOWAVirtualDirectory, etc."
Import-PSSession $OnPremExchSession -DisableNameChecking -ErrorAction stop -Prefix op
} else {
Import-PSSession $OnPremExchSession -DisableNameChecking -ErrorAction stop -Verbose
}
},
"Control+Alt+E"
)
$connectMenu.SubMenus.Add(
"Skype for Business Online", {
if (!$O365ISECREDENTIAL) {$O365ISECREDENTIAL = (get-credential)}
Import-Module LyncOnlineConnector -ErrorAction stop
$sfboSession = New-CsOnlineSession -Credential $O365ISECREDENTIAL -ErrorAction stop
},
"Control+Alt+K"
)
$connectMenu.SubMenus.Add( "Sharepoint Online", {
if (!$O365ISECREDENTIAL) {$O365ISECREDENTIAL = (get-credential)}
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking -ErrorAction Stop
write-verbose "Enter your Sharepoint Online Domain. `nFor instance, enter 'contoso' if your site is 'contoso.sharepoint.com'"
$DomainHost = read-host "Sharepoint Online Domain"
Connect-SPOService -Url "https://$($DomainHost)-admin.sharepoint.com" -credential $O365ISECREDENTIAL -ErrorAction stop
},
"Control+Alt+S"
)
$connectMenu.SubMenus.Add( "Clear Cached Credentials", {
if (!$O365ISECREDENTIAL) {$O365ISECREDENTIAL = $null}
},
"Control+Alt+8"
)
#Microsoft O365 Menus End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment