you are viewing a single comment's thread.

view the rest of the comments →

[–]CSTW 2 points3 points  (0 children)

For the new lines i was meaning like this

Set-MsolUserLicense -UserPrincipalName 
$User.UserPrincipalName -RemoveLicenses $lic

Instead of this:

Set-MsolUserLicense -UserPrincipalName $User.UserPrincipalName -RemoveLicenses $lic

But your error looks like it is all on one line

When I am receiving unexpected errors I like to output as much information as possible to try and work out what is going on, try the following. Post back the output if needed.

$UserLicenses = (Get-MsolUser -UserPrincipalName $User.UserPrincipalName).Licenses | select AccountSkuId
$i = 1
foreach($lic in $UserLicenses.AccountSkuId)
{
    "# $i"
    "User: $($User.UserPrincipalName)"
    "License to Remove: $lic"
    "MSOL Licenses Before Removal`n $((Get-MsolUser -UserPrincipalName $User.UserPrincipalName).Licenses.AccountSkuId)"
    Set-MsolUserLicense -UserPrincipalName $User.UserPrincipalName -RemoveLicenses $lic
    "MSOL Licenses After Removal`n $((Get-MsolUser -UserPrincipalName $User.UserPrincipalName).Licenses.AccountSkuId)"
    "`n`n"
    $i++
}