Forum Discussion
Remove licenses from users office 365
Hi,
I trying with no success to remove licenses from users.
I tried script from Microsoft docs but it`s not working.
I created txt file with the user upn.
after I runned the script I getting the next error:
Set-MsolUserLicense : User Not Found. User: .
At line:4 char:1
+ Set-MsolUserLicense -UserPrincipalName $x[$i] -RemoveLicenses "oranim ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [Set-MsolUserLicense], MicrosoftOnlineException
+ FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.UserNotFoundException,Microsoft.Online.Administration.Automation.SetUserLicense
My target is to remove from Students users they license from txt file or csv file.
Thanks.
- SchnittlauchSteel Contributor
- dannytveriaBrass Contributor
- SchnittlauchSteel Contributor
Hi dannytveria,
$_.UserPrincipalName is null. Do you have a list of the users, you want to remove the licenses? (Maybe they are all in the same AD Group, idk.)
If yes, than go and make their own variable ($Students for example) to remove ther licenses instead of $_.UserPrincipalName.Im wondering why the variable is null.
- Bestia1Copper ContributorI had the same problem during a long time
- SchnittlauchSteel Contributorhow u solved it?
- dannytveriaBrass ContributorI used the same script but change some arguments:
Connect-AzureAD
Connect-MsolService
[string[]]$x=Get-Content "D:\Logs\O365\Students with all licesnse\Bulk\Remove license test.txt"
for ($i=0; $i -lt $x.Count; $i++)
{
Set-MsolUserLicense -UserPrincipalName $x[$i] -RemoveLicenses "License SKU"
}