0
votes

I have an Office 365 tenant with multiple license plans and I'm trying to disable certain features of the E3 plan in bulk via Powershell.

Here's what I've got:

$ENTERPRISEPACK=New-MsolLicenseOptions -AccountSkuId companyname:ENTERPRISEPACK -DisabledPlans "FLOW_0365_P2", "POWERAPPS_0365_P2"

Import-CSV c:\scripts\inputfiles\e3users.csv | foreach-object -process { Set-MsolUserLicense -UserPrincipalName $_.upn -LicenseOptions $ENTERPRISEPACK -Verbose}

The issue that I'm running into, is that I can verify the users exist, and import the CSV as valid, but I get an error for every user in my CSV:

Set-MsolUserLicense : User Not Found.  User: .

This is pretty frustrating, as I only want to disable the features for all E3 users (which would be in my CSV) and this command works when you run it as:

$ENTERPRISEPACK=New-MsolLicenseOptions -AccountSkuId companyname:ENTERPRISEPACK -DisabledPlans "FLOW_0365_P2", "POWERAPPS_0365_P2"

Set-MsolUserLicense -UserPrincipalName [email protected] -LicenseOptions $ENTERPRISEPACK -Verbose

As you can see, the difference here is that I'm running it with one username entered specifically.

It just makes sense to me that I'd be able to pipe it input and run through a loop, but I'm missing something.

Please help?

1

1 Answers

0
votes

I was able to get this figured out on my own.

Frustratingly enough, piece number 1 is that "Set-MSOLUserLicense" only accepts pipeline input for UPNs out of a text file, and not a CSV.

Second, for some odd reason, the ServicePlans I'm trying to disable do not seem to be recognized when using double quotes.

This is what I ended up with:

$ENTERPRISEPACK=New-MsolLicenseOptions -AccountSkuId company:ENTERPRISEPACK -DisabledPlans 'FLOW_O365_P2','POWERAPPS_O365_P2','RMS_S_ENTERPRISE'

Get-Content "C:\scripts\inputfiles\E3users.txt" | foreach {Set-MsolUserLicense -UserPrincipalName $_ -LicenseOptions $ENTERPRISEPACK

And, since the -Verbose switch wasn't working, I added a script block to kick out logging. So, the command and the logging block look like this:

Get-Content "C:\scripts\inputfiles\E3users.txt" | foreach {Set-MsolUserLicense -UserPrincipalName $_ -LicenseOptions $ENTERPRISEPACK -ea silentlycontinue -ev +action


# if there were no errors, write to the screen and file what was done
if($action.count -eq 0)
{
 Write-Host -ForegroundColor Green "Changed license for" $_
 Write-output $_ | Out-File C:\scripts\OutputFiles\FeatureDisable\logs\LicenseSuccesslogEnterprise04072017.csv -Append
}
# if the initial command failed, then write to a failure logfile 
if($action.count -eq 1)
{
 Write-Host -foreground Yellow "Failed to change license for" $_
 Write-Output $_ | out-file C:\scripts\OutputFiles\FeatureDisable\logs\LicenseFailurelogEnterprise04072017.csv -Append
}
Clear-Variable -Name action}