May 05 2021 02:10 AM
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.
May 05 2021 07:07 AM - edited May 05 2021 07:07 AM
May 05 2021 10:21 PM
May 05 2021 11:52 PM - edited May 05 2021 11:58 PM
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.
May 06 2021 12:24 AM
@dannytveria Otherwise you can try it with an foreach loop something looking like this
$UserCSV = import-csv -path C:\Users\Schnittlauch\AllUsersInACsvFile.csv
foreach ($user in $UserCSV.ColumnWithTheUsers)
{
Set-MsolUserLicense -UserprincipalName $user -removeLicenses "oranimlive:STANDARDWOFFPACK_IW_STUDENT"
}
May 06 2021 12:34 AM
May 11 2021 12:57 AM
May 11 2021 04:46 AM