office365 - Trying to set user licenses in Office 365 via Powershell -


i have office 365 tenant multiple license plans , i'm trying disable features of e3 plan in bulk via powershell.

here's 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 i'm running into, can verify users exist, , import csv valid, error every user in csv:

set-msoluserlicense : user not found.  user: . 

this pretty frustrating, want disable features e3 users (which in csv) , command works when run as:

$enterprisepack=new-msollicenseoptions -accountskuid companyname:enterprisepack -disabledplans "flow_0365_p2", "powerapps_0365_p2"  set-msoluserlicense -userprincipalname testuser.here@domain.com -licenseoptions $enterprisepack -verbose 

as can see, difference here i'm running 1 username entered specifically.

it makes sense me i'd able pipe input , run through loop, i'm missing something.

please help?

i able figured out on own.

frustratingly enough, piece number 1 "set-msoluserlicense" accepts pipeline input upns out of text file, , not csv.

second, odd reason, serviceplans i'm trying disable not seem recognized when using double quotes.

this ended 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 -verbose switch wasn't working, added script block kick out logging. so, command , logging block this:

get-content "c:\scripts\inputfiles\e3users.txt" | foreach {set-msoluserlicense -userprincipalname $_ -licenseoptions $enterprisepack -ea silentlycontinue -ev +action   # if there no errors, write screen , file 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 initial command failed, write failure logfile  if($action.count -eq 1) {  write-host -foreground yellow "failed change license for" $_  write-output $_ | out-file c:\scripts\outputfiles\featuredisable\logs\licensefailurelogenterprise04072017.csv -append } clear-variable -name action} 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -