Disabling users from powershell - taking it a few steps further?

Hello everyone,
I have a question regarding performing some more granular actions to user accounts via PS.
Currently, I have the trusty little command that allows me to disable accounts from a TXT file

Get-Content "C:\My Documents\Accounts.txt" | ForEach { Set-MsolUser -UserPrincipalName $_ -BlockCredential $true }

This works fine, but what if I want to go a little further, for example, removing their licenses, or signing them out of all their sessions
How would I get that done? I would think that it will be a much more complicated line than what I posted above?

Any insight would be great

Thanks

Get-Content "C:\My Documents\Accounts.txt" | ForEach {
Set-MsolUser -UserPrincipalName $_ -BlockCredential $true
Set-MsolUserLicense -UserPrincipalName $_ -RemoveLicenses "my:license"
}

To remove a licenes use the set-msoluserlicense cmdlet or Microsoft Graph PowerShell

Does $_ -RemoveLicenses “my:license” remove every license on the account of the user in the accounts.txt file?

Did I ready that correctly?

How long would it take you to test that with a single test user? :wink:

Hello Olaf,
Thanks for the heads up.
I ran this line

Get-Content "C:\temp\Accounts.txt" | ForEach {Set-MsolUser -UserPrincipalName $_ -BlockCredential $true | Set-MsolUserLicense -UserPrincipalName $_ -RemoveLicenses "my:license"}

The command runs successfully it blocks the accounts in the TXT file but it doesn’t seem to be removing the license for the users in that text file. I waited about 15 minutes but it doesn’t do much of anything.

Is there something I need to do here?

Thanks!

I will quote myself: