Disable-MSOLServices.ps1

function Disable-MSOLServices {
  #region License Options
  $msolAccountSKU = Get-MsolAccountSku | ? {$_.AccountSkuId -like "*enterprisepack*"}
  $msolServices = $msolAccountSKU.ServiceStatus.ServicePlan
  $disabledServices = @() # Create new array to store services we wish to disable.
  foreach ($s in ($msolServices | ? {$_.TargetClass -eq 'User' -and `
                                   $_.ServiceName -notlike '*office*' -and `
                                   $_.ServiceName -notlike "*exchange*" -and `
                                   $_.ServiceName -notlike "*SharePoint*" -and `
                                   $_.ServiceName -notlike "*Teams*" -and `
                                   $_.ServiceName -notlike "*MCOStandard*"
                                   })) {
    Write-Host "ServiceName: " -NoNewline
    Write-Host $s.ServiceName.PadRight(20) -ForegroundColor Green -NoNewline
    Write-Host "ServiceType: " -NoNewline
    Write-Host $s.ServiceType.PadRight(20) -ForegroundColor Green -NoNewline
    Write-Host "TargetClass: " -NoNewline
    Write-Host $s.TargetClass.ToString().PadRight(20) -ForegroundColor Green
    $disableit = Read-Host "Disable It? (Respond Y, N, or blank. Blank treated as N.)"
  
    while ($disableit -notin 'y','Y','n','N','') {Write-Host 'Anser must be Y or N'; $disableit = Read-Host "Disable It?"}
    if ($disableit -in 'y','Y') { $disabledServices += $s.ServiceName ; Write-Host "Disabling $($s.ServiceName)" -ForegroundColor Red; Write-host ""}
    if ($disableit -in 'n','N','') {Write-Host "Keeping $($s.ServiceName)" -ForegroundColor Yellow; Write-Host ""}
  
  }
  $msolLicenseOptions = New-MsolLicenseOptions -AccountSkuId $msolAccountSKU.AccountSkuId -DisabledPlans ($disabledServices -join ',')

  Write-Host "Disabling Features: " -NoNewline
  Write-Host "$($msolLicenseOptions.DisabledServicePlans)" -ForegroundColor Red
  #endregion License Options
  #region Get Users Prep
  $msolUsers = Get-MsolUser -All  | ? {$_.isLicensed -eq $true}

  $msolUsers = $msolUsers | ? {$_.Licenses.AccountSkuID -eq $msolAccountSKU.AccountSkuId} # Only want users matching our AccountSKUId we're creating options for
  #endregion Get Users Prep
  Read-Host "Continue disabling these features on $($msolusers.Count) users?"
  #region Set Options on Licensed Users
  $userindex = 0
  foreach ($u in $msolUsers) {
    Write-Progress -Activity 'Setting Disabled Licenses' -Status "Updating User Licenses" -CurrentOperation "$($u.UserPrincipalName)" -PercentComplete ($userindex/$msolUsers.count)
    Set-MsolUserLicense -UserPrincipalName $u.UserPrincipalName -LicenseOptions $msolLicenseOptions -Verbose
    $userindex++
  }
  #endregion Set Options on Licensed Users
}