Simplify Cloud Services Management in Microsoft 365 with PowerShell

In this post, we will share a PowerShell script designed to simplify the management of cloud services in Microsoft 365. Effectively managing cloud services is essential for ensuring that your organization’s resources are utilized efficiently and securely. This script allows administrators to quickly gather information about active services, enable or disable them, and monitor their status, streamlining the management process.
Here is the PowerShell script for managing Microsoft 365 cloud services:

# Connect to Microsoft 365
$credential = Get-Credential
Connect-MsolService -Credential $credential
# Retrieve all users and their assigned cloud service licenses
$users = Get-MsolUser -All | Select-Object DisplayName, UserPrincipalName, Licenses
# Display cloud services information
foreach ($user in $users) {
    Write-Host "User: $($user.DisplayName) - Email: $($user.UserPrincipalName)"
    foreach ($license in $user.Licenses) {
        Write-Host "  License: $($license.AccountSkuId)"
    }
}
# Example: Disable a specific service for a user
$userToDisable = "[email protected]"
$serviceToDisable = "Office 365 Enterprise E3"
Set-MsolUserLicense -UserPrincipalName $userToDisable -RemoveLicenses $serviceToDisable
Write-Host "Service $serviceToDisable has been disabled for user $userToDisable."