Getty Images/iStockphoto

Slow Office 365 admin portal problems? Give PowerShell a try

IT work is frustrating enough without having to deal with sluggish admin center performance. See how PowerShell makes Microsoft service management less of a chore.

Frustrated by sluggish responses from the Office 365 admin center? A switch to PowerShell can accelerate the execution of management tasks for a better administrative experience.

Microsoft continues to expand the number of enhancements and new features to Office 365, revamping the admin portal constantly. Administrators need to be vigilant to find new screens and options within the portal to manage security, compliance and administration of all Office 365 services. Rather than navigate through the numerous pages to perform recurring tasks through a browser, PowerShell scripting might be the best tool to support a more efficient and automated approach.

Changes to the web management console outpace available study guides, requiring many administrators to turn to video tutorials, blog posts and exploring the site to learn how to use the new management functionality. Administrators will find they can use PowerShell scripts to handle most of their day-to-day administrative tasks -- in some cases, with even more capabilities than the admin center. There are times when the admin portal is slow to respond, which makes PowerShell another option if a time-sensitive project requires quick attention.

Areas where PowerShell outshines the admin center

PowerShell is Microsoft's command-line shell scripting language designed to assist administrators who manage and configure Microsoft services and products. It is capable of small tasks, such as sending a restart command to a remote server or extracting a list of unlicensed users from the Office 365 platform.

PowerShell is ideally suited for a range of repetitive tasks not suited to run from the admin portal. Some of these activities include getting a list of licensed users with disabled accounts, generating a list of users with multifactor authentication enabled, disabling multiple accounts or deleting a SharePoint site that has several subsites.

How to disable access to the Office 365 portal

Limiting accounts from accessing the admin portal area can be done in Active Directory. The changes will sync with Office 365 to disable those accounts, but some tenants may want to maintain some accounts in Active Directory while disabling their sign-in to Office 365.

To disable the sign-in for a large list of users from the web portal involves making changes from the active users section. The admin selects one name at a time from the grid. Depending on the list size, this task could take a long time.

Edit active users' sign-in status
The method of manually selecting the users in the admin portal to change their sign-in status is a slow process.

Next, select the edit sign-in status option. The web admin portal does not allow searching for additional users after this selection process. To disable multiple names at once requires scrolling down and searching visually for the name, not by keyword. This limit makes it almost unusable for large enterprise accounts.

PowerShell does not have the drawbacks of the admin portal. There is no limitation to look up users by name. The following PowerShell script reads the list of users to edit, then performs the action on each of the email addresses or accounts listed in the file. 

The file format should be in plaintext email addresses. One address per line as shown below:

[email protected]

[email protected]

[email protected]

Get-Content "C:\My Documents\Accounts.txt" | ForEach { Set-MsolUser -UserPrincipalName $_ -BlockCredential $true }

The automation aspect of PowerShell means this script can be triggered manually or scheduled to run periodically.

Deleting parent sites that contain subsites in SharePoint Online

PowerShell is a better management choice than the admin portal when it's time to delete a SharePoint site with multiple subsites.

From the web portal, an administrator would need to delete all subsites manually before the parent site can be deleted, otherwise the system will generate an error message. This could require a lot of manual effort depending on how many subsites the operation involves.

The PowerShell method can reduce this SharePoint work significantly via a script that reads all subsites under a parent site, then automatically deletes all these discovered subsites before it removes the parent site. This approach requires a handful of parameters to be entered interactively by the administrator, including their credentials, the admin portal URL and the site to delete.

function remove-SPOWeb ($web){
 #Uses the to be deleted variable as start point
 $context = New-Object Microsoft.SharePoint.Client.ClientContext($web)   
 $context.Credentials = $SPOCredentials
 $web = $context.Web 
 $context.Load($web)
 $context.Load($web.Webs)
 #send the request containing all operations to the server

 try{
  $context.executeQuery()
#remove any subweb if present
  if ($web.Webs.Count -ne 0){
   foreach ($subweb in $web.Webs){
    remove-SPOWeb($subweb.url)
   }
  }

Write-Host "Info: Removing $($web.url)" -foregroundcolor green
  $web.DeleteObject()
  $Context.ExecuteQuery()
 }
 catch{
  write-host "Error: $($_.Exception.Message)" -foregroundcolor green
 }
}
function remove-SPOWebs{
#variables that needs to be set before starting the script
$userName = "[email protected]"
$adminUrl = "https://TenantName-admin.sharepoint.com"

# Let the user fill in the site that has to be deleted
$toBeDeleted = Read-Host "Please enter the full url of the site that needs to be deleted (e.g. https://TenantName.sharepoint.com/sites/rootsite/subsite"

# Let the user fill in their password in the PowerShell window
$password = Read-Host "Please enter the password for $($userName)" -AsSecureString

# set SharePoint Online and Office 365 credentials
$SPOCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $password)
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $password

#connect to to Office 365
try{
Connect-SPOService -Url $adminUrl -Credential $credentials
write-host "Info: Connected succesfully to Office 365" -foregroundcolor green
}
catch{
write-host "Error: $($_.Exception.Message)" -foregroundcolor red
Break delete-SPOSites
}

#verify if site already exists in SharePoint Online
$siteExists = get-sposite | where{$_.url -eq $toBeDeleted}
#remove web if site isn't an site collection
if ($siteExists -eq $null) {
remove-SPOWeb($toBeDeleted)
}
else {
Remove-SPOSite -Identity $siteExists -NoWait -confirm$false
write-host "Info: The site collection $($toBeDeleted) has been removed" -foregroundcolor green
}
}
remove-SPOWebs

PowerShell excels at reporting in Office 365

Another area where the Microsoft 365 admin center is more limited than PowerShell is reporting.

The portal reports section is limited to productivity score and usage, making it difficult to get more granular information. Exchange Online's PowerShell commands, especially the ones in Microsoft's Exchange Online PowerShell V2 module, perform bulk tasks and activities quickly, even when dealing with thousands of mailboxes. PowerShell's capabilities make quick work of changes that would take a significant amount of time and effort from the admin portal.

The screenshot here shows user email statistics from the usage report section of the admin portal. Administrators have no way to filter the data, forcing them to export the results to a CSV file and then use Microsoft Excel or another spreadsheet tool to narrow the results to the specific users they need.

Office 365 email usage report
The Office 365 admin portal does not provide a way to create customized reports.

A PowerShell script can retrieve the same data using the following command along with any desired filters:

Get-MailTrafficTopReport
   [-Action <MultiValuedProperty>]
   [-AggregateBy <String>]
   [-Direction <MultiValuedProperty>]
   [-Domain <MultiValuedProperty>]
   [-EndDate <DateTime>]
   [-EventType <MultiValuedProperty>]
   [-Page <Int32>]
   [-PageSize <Int32>]
   [-ProbeTag <String>]
   [-StartDate <DateTime>]
   [-SummarizeBy <MultiValuedProperty>]
   [<CommonParameters>]

The following example returns a report with email statistics between a date range:

Get-MailTrafficTopReport -StartDate 08/04/2021 -EndDate 08/05/2021

In another example, when a large company changes domain names, it will need to update the primary SMTP address of all its users. The Exchange admin web portal has the functionality to change those configurations one user at a time, but dealing with hundreds or thousands of accounts this way would be slow and tedious. With a PowerShell script, this same task would require minimal effort and would be completed quicker.

Office 365 management via PowerShell can be a necessity

The Office 365 admin portal is a practical tool for many ad hoc security, compliance and service configuration tasks. But point-and-click management is not practical for some procedures and any performance issues in the portal will make it difficult to get work done in a meaningful time frame.

For advanced activities that require far more complex steps or when the changes deal with a large number of user property changes, PowerShell is a far more robust way to handle those changes. Some features can only be changed through PowerShell, making it critical for Office 365 admins to understand how to work with PowerShell commands and script execution to fully manage the platform.

Dig Deeper on Microsoft messaging and collaboration