We have a constant churn of staff, as does any large organisation. One of the challenges is to ensure that anyone who has left has their account disabled in AD. All good, we have that process. We also use Azure AD Sync to sync users to our Office 365 tenant.
Disabling a user however, does not remove the licence assigned them, so I decided to create a simple PowerShell script that I can run periodically to find all the blocked users in Office365 and remove any licences they had.
This script requires PowerShell 5..
#clear the screen CLS #Lets log the output.. Remeber to change this to a location you want! Start-Transcript -path C:\temp\output.txt -append #Connect To your tenant.. Connect-MsolService #get a list of all users who's sign in status is blocked.. Write-Output "getting Blocked users..." $users = Get-MsolUser -All | Where-Object {$_.BlockCredential -eq "True"} | Select -Property UserPrincipalName Write-Output "Starting unlicense module.." #remove licences from these users.. foreach ($user in $users) { #ok, lets see what license they have.. $license = Get-MsolUser -UserPrincipalName $user.UserPrincipalName | Select-Object -ExpandProperty Licenses #make sure you change this to your country! Set-MsolUser -UserPrincipalname $user.UserPrincipalName -UsageLocation "GB" #go ahead and remove the licence if ($license.AccountSkuId -ne $null) { Set-MsolUserLicense -UserPrincipalName $user.UserPrincipalName -RemoveLicense $license.AccountSkuId #lets log what we did so we can report on it. Managers love reports.. Write-Output $user.UserPrincipalName removed $license.AccountSkuId } } Write-Output "Finished" Stop-Transcript
eufy Security, eufyCam 2C Wireless Home Security Camera System, 180-Day Battery Life, HD 1080p, IP67 Weatherproof, Night Vision, Compatible with Amazon Alexa, 2-Cam Kit, No Monthly Fee
£229.99Picture Perfect Surveillance - Live-stream and record footage in crystal clear 1080p HD. The 135° diagonal field of view allows you to see exactly what is happening in and around your home. Half-Year Security from 1 Charge - Avoid frequent trips to c... read more
(as of 10th April 2021 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)LEMFO Smart Watch For Men, Full Touch Screen With 24 Sports Modes Smartwatch, Heart Rate Monitor Blood Pressure Sleep Counter GPS Activity Tracker, IP68 Waterproof Smart Watches For Android IOS
£34.86【24 Sports Modes & Big UI Design】This 1.3 inch full touch screen smart watch for men with 24 sports modes, such as swimming, basketball, tennis, badminton, etc., which can satisfy your various sports styles. The large UI design of this smart watch al... read more
(as of 11th April 2021 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Palit GeForce RTX 3080 GamingPro 10GB GDDR6X Ray-Tracing Graphics Card, 8704 Core, 1440MHz GPU, 1710MHz Boost, 3 x DisplayPort, HDMI, Advanced TurboFan 3.0
Core Clock 1440 MHz / Boost Clock 1710 MHz / 10 GB GDDR6X / 19 GBps / 320 Bit / 8704 CUDA Cores PCI-Express 4.0 x 16, DisplayPort 1.4a x 3, HDMI 2.1 Powered by Ampere—NVIDIA’s 2nd gen RTX architecture Triple A Die Casting Plate Kit, Double U Heat Pip... read more
(as of 11th April 2021 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Blink Outdoor | Wireless, weather-resistant HD security camera with two-year battery life and motion detection | 1-Camera System
£89.99Blink Outdoor is a wire-free battery-powered HD security camera that helps you monitor your home day or night with infrared night vision. With long-lasting battery life, Blink Outdoor runs for up to two years on two AA lithium batteries (included). B... read more
(as of 11th April 2021 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)