I’ve added code to monitor session states and put status in title-bar. When you hit ‘enter’ key, it will update session states in title-bar. Some people may not want this, so you’ll need to use the switch (-IncludeSessionStates) when you run script. See bottom of blog for details.
I’ve added support for Teams PowerShell, and fixed an issue with Azure AD v2 connection. I’ve updated the requirements for Azure AD v1, as Microsoft has removed the old MSI file downloads. If you have not previously installed these MSI modules, your only option is to use PowerShellGet to install Azure AD v1. PowerShellGet requires PowerShell version 5 or above. This is also true for Azure AD v2 and Teams modules. Direct downloads below.
If PowerShell session is running as Administrator, it will leave “Administrator: ” in the window title and append the tenant name. Added xml section to store credentials, which is locked down to user. For initial login, using try/catch.
(Note: This script does not support MFA, I’ll publish another blog soon that supports MFA).
I wrote this script to connect to all the main Office 365 services in a single PowerShell window, which are available across E1 and E3 licenses. The main services are (Azure AD [v1 & v2], Sharepoint Online, Skype 4B Online, Exchange Online, Teams and Compliance Center). You’ll need to install prerequisites before you can connect to all services. You’ll need 64-bit version of Windows because of the requirements for Skype for Business Online and Azure AD PowerShell modules.
The Office 365 account you use to connect with PowerShell must be a member of the Global Admin role. For more information about Office 365 permissions, see Office 365 Permissions.
You’ll need to install at least .NET Framework 4.5.2 and either Windows Management Framework 3.0 or 4.0. (Note: If you have NOT previously installed MSI modules for Azure AD v1, your only option now is to use PowerShellGet to install Azure AD v1, which requires Windows Management Framework 5.0 or greater).
- .NET Framework
- Windows Management Framework 3.0
- Windows Management Framework 4.0
- Windows Management Framework 5.1
You need to install modules that are required for Azure AD (v1 & 2), Teams, SharePoint Online, and Skype for Business Online (see below). Exchange Online (non-MFA) does not require any module installation. (Note: Azure AD (v1 & v2) and Teams, require PowerShellGet for installation)
- Azure AD PowerShell v.1 (MSOL)
- Azure AD PowerShell v.2 (AzureAD)
- Microsoft Teams
- SharePoint Online PowerShell Module
- Skype for Business PowerShell Module (Note: latest requires MS Visual C++ Redistributable for VStudio 2017)
Windows PowerShell execution policy needs to be set to allow scripts to run. To do this, run the following command in an elevated Windows PowerShell session (open PowerShell As Administrator). Type the following to allow the script to run in the current PowerShell session only.
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process –Force
For more information on execution policy, see Set-ExecutionPolicy.
Connect to Office 365 services
For easy access, place script in a folder near root volume (c:\Scripts), and call from any directory. The script will prompt for credentials by default, but if you want to suppress prompt and store credentials in the script or call from secure file, there is a section to do so – this can be helpful with Office 365 lab environments. Here is sample output.
Show Office 365 session states in Title bar
Exchange Online, Skype 4B Online, and Compliance Center all use Import-Session cmdlet to connect, so you can run Get-PSSession to see their current state as ‘Opened’. Since they all have different time-out parameters, they’ll eventually change to ‘Broken’ state. Sometimes you don’t realize this until you attempt to run a script block and receive an error. I decided to add the session states to the title bar, which will update every time the ‘Enter’ key is pressed. I did this by adding code to the default prompt function, although it will not overwrite it, but append to it (in case you have a custom prompt like I do). This only affects the current PowerShell window, and is not permanent. Not everyone will appreciate this, so to activate this feature, add the switch (-IncludeSessionStates) when running the script – see below.
Here’s an example of what the title bar will look like. You can see initially I opened connections around 1am, but when I hit the enter key at 9:32am, it updated the title bar to show the sessions had become ‘Broken’. Running ‘Get-PSSession | Remove-PSSession’ will clear the sessions and title bar.
Download script from this link: connect_v5.8.2