powershell/sysadmin beginner here, im trying to automate the process when an employee leaves a company from an IT perspective - disabling the AD account, moving it into a different OU, removing licenses, removing group memberhsip.
Im trying to fit this into a single powershell script, disabling the AD account and moving it was easy but im running into trouble when trying to remove licenses.
My idea was getting all the assigned licenses and looping it with a foreach command.
What i basically have right now is this:
$givemelicenses = get-msoluser -userprincipalname email@example.com | select-object licenses
output of this is :
Was just writing a similar answer to what Olaf proposed.
Also when you use a cloud-synced AD-group for licensing you probably don’t need to mix AAD and AD commands in your script for disabling users as you remove the user from the local AD-group and on next sync it will automagically remove the user from the cloud-group and remove the license.
Thank you for the suggestions but i dont want to go around redesigning the system as it is, i would preferably get this script to work
I’ve made “some” headway, i did this:
$info = get-msoluser -userprincipalname firstname.lastname@example.org
I get this:
So i would just need to store this output as 2 separate values in an array which i can then process with foreach/set-msoluser combination.
Because if i manually do this:
set-msoluserlicense -userprincipalname email@example.com -removelicenses reseller-account:ATP_ENTERPRISE
The above cmd does in fact remove the said license, so i would just need to loop it for each value of the previous result.