Connect to Office 365 Exchange Online with Prerequisites Verification
Introduction
This script establishes a connection to Office 365 Exchange Online. Before establishing a connection, it checks the prerequisites that required by Office 365 Exchange Online.
Scenarios
Nowadays, Office 365 administrators are required to remember a long command to establish a connection to Office 365 Exchange Online. It’s not easy to remember all the parameters clearly. It’s better to save that command in a Windows PowerShell
script. Additionally, it’s worth to check all the prerequisites to help Office 365 administrators to troubleshoot the connection issues.
Script
This script may be executed in a Windows PowerShell V1 console, so it doesn’t use any features that are available in Windows PowerShell V2. You can use this script in the following way:
- Download the script and copy it to a Windows client or server computer with Windows PowerShell installed.
- Run the script in a Windows PowerShell console.
Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.
PowerShell
Edit|Remove
powershell
foreach ($prerequisiteName in $prerequisites.Keys.GetEnumerator()) {
$report = New-Object System.Object
$report | Add-Member -MemberType NoteProperty -Name "Prerequisite" -Value $prerequisiteName
if ((Invoke-Expression "Test-OSC$prerequisiteName") -eq $false) {
$report | Add-Member -MemberType NoteProperty -Name "CheckResult" -Value "Failed"
} else {
$report | Add-Member -MemberType NoteProperty -Name "CheckResult" -Value "Passed"
}
if ((Invoke-Expression "Test-OSC$prerequisiteName") -eq $false) {
$report | Add-Member -MemberType NoteProperty -Name "Suggestion" -Value $($prerequisites[$prerequisiteName])
} else {
$report | Add-Member -MemberType NoteProperty -Name "Suggestion" -Value "None."
}
$reports += $report
}
foreach ($prerequisiteNamein$prerequisites.Keys.GetEnumerator()) {
$report = New-Object System.Object
$report|Add-Member-MemberType NoteProperty -Name "Prerequisite"-Value $prerequisiteNameif ((Invoke-Expression"Test-OSC$prerequisiteName") -eq $false) {
$report|Add-Member-MemberType NoteProperty -Name "CheckResult"-Value "Failed"
} else {
$report|Add-Member-MemberType NoteProperty -Name "CheckResult"-Value "Passed"
}
if ((Invoke-Expression"Test-OSC$prerequisiteName") -eq $false) {
$report|Add-Member-MemberType NoteProperty -Name "Suggestion"-Value $($prerequisites[$prerequisiteName])
} else {
$report|Add-Member-MemberType NoteProperty -Name "Suggestion"-Value "None."
}
$reports+= $report
}
Examples
Example 1: How to run this script on a Windows Server 2003 R2 machine with Windows PowerShell 1.0 installed only.

Example 2: How to run this script on a Windows Server 2003 R2 machine. Windows PowerShell 2.0 and WinRM 2.0 are installed. Before running this script, WinRM service is stopped.

Note You can choose to start WinRM service. It’s because that the code for checking the authentication setting of WinRM triggers this prompt.
Example 3: How to run the script from a non-elevated Windows PowerShell console on a Windows 7 computer.

Note If the script is running in a non-elevated console, WinRM authentication setting cannot be retrieved. So the CheckResult is pending and the Suggestion is not
available.
Example 4: Run the script from an elevated Windows PowerShell console on a Windows 7 computer.

Additional Resources
Technical Resources: