Control Services for Office 365

Some customers want to control the services that are being pushed by Microsoft to ever expanding office 365 portfolio.

They want to first explore these before activating it for users, we were recently in such a situation where cutomer wants to disable few services.

Customer wants that these should be disabled for all Users as of now.

This script has been written to disable the services for all the o365 users without affecting their existing services.

Download & extract the script from below link, update the below variables :

https://gallery.technet.microsoft.com/scriptcenter/Control-New-for-Office-365-8d30fed8?redir=0

$licenseent = “Company:ENTERPRISEPACK”  #This is the vaule that you can get by using Get-MsolAccountSku

$svctodisable = @(“FLOW_O365_P2”, “TEAMS1”) # services that you want to disable for all users

Use below commands to get services value:

PS C:\> $a=Get-MsolUser -UserPrincipalName sukhijaS@techwizard.cloud

PS C:\> $a.Licenses.servicestatus

capture

Run the script , it will connect to MSOL (will prompt you for userid & password), if you are already connected to MSOL than just

prepend # to Connect-MsolService inside the script before execution.

Output in csv will be placed under report folder.

I hope this script will assist you in the described situation.

<#     
    .NOTES 
    =========================================================================== 
     Created on:       11/21/2016 4:18 PM 
     Created by:       Vikas Sukhija 
     Organization:      
     Filename:         ControlNewLicenseFeatures.ps1 
    =========================================================================== 
    .DESCRIPTION 
        A description of the file. 
#> 
$Error.clear() 
$date1 = get-date -format d 
$date1 = $date1.ToString().Replace("/""-"$time = get-date -format t 
 
$time = $time.ToString().Replace(":""-"$time = $time.ToString().Replace(" """) 
 
$report = ".\report" + "\" + "Report_DisabledSVC" + $date1 + "_" + $time + "_.csv" 
 
$collusers = @() 
$collection = @() 
 
###################Variables to be defined####################### 
 
$licenseent = "Company:ENTERPRISEPACK" 
$svctodisable = @("FLOW_O365_P2""POWERAPPS_O365_P2""TEAMS1") 
 
##########################Define functions############## 
function ProgressBar { 
    [CmdletBinding()] 
    param 
    ( 
        $title 
    ) 
     
    For ($i = 1; $i -le "10"$i++) { 
        Start-Sleep 1; 
        Write-Progress -Activity $Title -status "$i" -percentComplete ($i /10 * 100) 
    } 
} 
##########Connect to MSOL##################### 
Connect-MsolService 
 
$AllLicensingPlans = Get-MsolAccountSku | Where-Object{ $_.AccountSkuId -eq $licenseent } 
 
$allusers = get-msoluser -All | Where-Object{ $_.isLicensed -eq $true } 
if ($error) { Write-Host "Exiting Script -- Error Fetching MSOL Users" -ForegroundColor Red; ProgressBar -title "Error Fetching MSOL Users"exit } 
 
################Loop thru services for each user##### 
 
foreach ($user in $allusers) { 
    $status = $user.Licenses.servicestatus 
    $upn = $user.userprincipalname 
     
    if ($status -ne $null) { 
         
        foreach ($svc in $status) { 
            $svcnm = $svc.Serviceplan.ServiceName 
            $svcsts = $svc.ProvisioningStatus 
            foreach ($newsvc in $svctodisable) { 
                if (($svcnm -eq $newsvc-and ($svcsts -ne "Disabled")) { 
                    Write-Host "$svcnm is enabled for user $upn" -foregroundcolor Magenta 
                    $collusers +$upn 
                } 
            } 
        } 
    } 
} 
$collusers = $collusers | Select-Object -Unique 
if ($error) { Write-Host "Exiting Script -- Error Collecting MSOL Users" -ForegroundColor Red; ProgressBar -title "Error  Collecting MSOL Users"exit } 
####loop thru collected user to disable required services witout affecting enabled ####### 
$collusers | foreach-object{ 
    $mcoll = "" | Select-Object UserPrincipalName, DisabledSVC 
    $USR = $_ 
    $lic1 = get-msoluser -UserPrincipalName $USR 
     
    foreach ($sts in $lic1.Licenses) { 
        if ($sts.AccountSkuId -eq $licenseent) { 
            $status1 = $sts.servicestatus 
        } 
    } 
     
    $mcoll.UserPrincipalName = $USR 
     
    if ($status1 -ne $null) { 
        $collnmsts = @() 
        foreach ($svc1 in $status1) { 
            $svcnm1 = $svc1.Serviceplan.ServiceName 
            $svcsts1 = $svc1.ProvisioningStatus 
            if ($svcsts1 -eq "Disabled") { 
                $collnmsts +$svcnm1 
            } 
        } 
        $collnmsts +$svctodisable 
        $mcoll.DisabledSVC = $collnmsts 
        $O365Licences = $null 
        for ($i = 0; $i -lt $AllLicensingPlans.Count; $i++) { 
            $O365Licences = New-MsolLicenseOptions -AccountSkuId $AllLicensingPlans[$i].AccountSkuId -DisabledPlans $collnmsts 
        } 
        Write-Host "Processing ........................ $USR" -ForegroundColor Green 
        Set-MsolUserLicense -UserPrincipalName $USR -LicenseOptions $O365Licences 
        if ($error) { 
            Write-Host "Exiting Script -- Error setting License for $USR" -ForegroundColor Red; ProgressBar -title "Error seeting License for $USR"exit 
        } 
    } 
    else { 
        Write-Host "Processing ........................ $USR" -ForegroundColor Green 
        $mcoll.DisabledSVC = "NA" 
    } 
    $collection +$mcoll 
} 
$collection | Select-Object UserPrincipalName, @{ Name = "DisabledSVC"; Expression = { $_.DisabledSVC } } | Export-Csv $report -NoTypeInformation 
#############################################################################

 

Thanks for reading and downloading

Tech Wizard

https://techwizard.cloud

https://syscloudpro.com/

 

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s