Everybody knows Office 365 contains a lot of functionality and all of them can be managed through the portal or via Powershell. But how to change a service, lets say Skype, from an unknow state (on or off)  to on? For all users in your organisation?



First, Powershell contains a lot of functionality and what is described above is possible, but how. The only knowledge I had was how to set all services for one user to on and the disable a few as shown below:




  • $UserCredential = Get-Credential

  • Connect-MsolService -Credential $UserCredential

  • $AccountSku=(Get-MsolAccountSku | Where {$_.SkuPartNumber -eq "ENTERPRISEPACK"}).AccountSkuId

  • $Full = New-MsolLicenseOptions -AccountSkuId $AccountSku -DisabledPlans  $null

  • $Selected = New-MsolLicenseOptions -AccountSkuId $AccountSku -DisabledPlans "FLOW_O365_P2", "POWERAPPS_O365_P2", "TEAMS1", "PROJECTWORKMANAGEMENT", "SWAY", "INTUNE_O365", "YAMMER_ENTERPRISE", "RMS_S_ENTERPRISE", "MCOSTANDARD", "EXCHANGE_S_ENTERPRISE

  • Set-MsolUserLicense -UserPrincipalName UPN -LicenseOptions $Full

  • Set-MsolUserLicense -UserPrincipalName UPN -LicenseOptions $Selected



The last two statements enables for the selected UPN all available services within the license and secondly removes the services selected. So it should be possible to enable only one service for all users with only the correct PowerShell code! See below the code I used to enable



# Retrieve AccountSkuId..

$AccountSkuId = (Get-MsolAccountSku | Where {$_.SkuPartNumber -eq "ENTERPRISEPACK"}).AccountSkuId



# Retrieve all service plans

$ServicePlans = (Get-MsolAccountSku | Where {$_.SkuPartNumber -eq "ENTERPRISEPACK"}).ServiceStatus



# Create logdir..

$LogDir="D:\Tools\PowerShell\Office365\UPN"

Remove-Item -Path "D:\Tools\PowerShell\Office365\UPN" -Recurse

New-Item $LogDir -ItemType directory



# Retrieve all licensed users..

$Users = (Get-MsolUser -All | where {$_.isLicensed -eq $true})



# Loop all users..

foreach ($User in $Users) {

    $upn = $user.UserPrincipalName

    foreach ($license in $user.Licenses) {

        if ($license.AccountSkuId -eq $AccountSkuId) {

            # Create logfile variable..

            $Log=$LogDir+"\"+$upn+".txt"



            # Empty arrays..

            $OriginalPlans = @()

            $NewPlans = @()



            # Loop all services..

            #   - FORMS_PLAN_E3                - Microsoft Forms (E3)

            #   - STREAM_O365_E3            - Stream for Office 365

            #   - Deskless                    - Microsoft Staffhub

            #   - FLOW_O365_P2                - Flow for Office 365

            #   - POWERAPPS_O365_P2            - PowerApps for Office 365

            #   - TEAMS1                    - Microsoft Teams

            #   - PROJECTWORKMANAGEMENT        - Microsoft Planner

            #   - SWAY                        - Sway

            #   - INTUNE_O365                - Mobile Device Management

            #   - YAMMER_ENTERPRISE            - Yammer Enterprise

            #   - RMS_S_ENTERPRISE            - Azure Rights Management

            #   - OFFICESUBSCRIPTION        - Office 365 ProPlus    

            #   - MCOSTANDARD                - Skype for Business Online (Plan 2)

            #   - SHAREPOINTWAC                - Office Online

            #   - SHAREPOINTENTERPRISE        - SharePoint Online (Plan 2)

            #   - EXCHANGE_S_ENTERPRISE        - Exchange Online (Plan 2)

            #

            foreach ($licenseStatus in $license.ServiceStatus) {

                $plan = $licenseStatus.ServicePlan.ServiceName

                $status = $licenseStatus.ProvisioningStatus

                if ($status -eq "Disabled") {

                    If ($plan -ne "FORMS_PLAN_E3" And $plan -ne "STREAM_O365_E3" And $plan -ne "Deskless" And $plan -ne "MCOSTANDARD") {

                        $NewPlans += $plan

                        }

                        $OriginalPlans += $Plan

                    }

                }



            # Sort arrays..

            $OriginalPlans = $OriginalPlans | select -Unique

            $NewPlans = $NewPlans | select -Unique

            

            If ($OriginalPlans -ne $NewPlans) {

                # Write output to logfile.

                write-output "Original disabled plan: $OriginalPlans" | tee-object -filepath $Log -append

                write-output "New disabled plan: $NewPlans" | tee-object -filepath $Log -append



                # create two license options, onw all enabled and one with Skype added..

                $LicenseEnabled = New-MsolLicenseOptions -AccountSkuId $AccountSkuId -DisabledPlans $null

                $LicenseOptions = New-MsolLicenseOptions -AccountSkuId $AccountSkuId -DisabledPlans $NewPlans

    

                # Alter license for user..

                Set-MsolUserLicense -UserPrincipalName $upn -LicenseOptions $LicenseEnabled

                Set-MsolUserLicense -UserPrincipalName $upn -LicenseOptions $LicenseOptions

            } Else {

                write-output "Original plan equal to new plan" | tee-object -filepath $Log -append

                }

            }

        }

    }



#



No comments

The author does not allow comments to this entry