How do i powershell several licenses from E3 to E1?

%3CLINGO-SUB%20id%3D%22lingo-sub-283119%22%20slang%3D%22en-US%22%3EHow%20do%20i%20powershell%20several%20licenses%20from%20E3%20to%20E1%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-283119%22%20slang%3D%22en-US%22%3E%3CP%3EWe%20are%20changing%20several%20accounts%20from%20E3%20to%20E1%20and%20I%20need%20a%20Method%20to%20automate%20this.%3C%2FP%3E%3CP%3EMy%20thought%20is%20to%20create%20a%20Text%20file%20with%20the%20Account%20names%20like%20Waldo%40mydomain.com%20and%20name%20it%20E3toE1Feed.txt%3C%2FP%3E%3CP%3EThen%20Run%3A%3C%2FP%3E%3CP%3EGet-Content%20%22D%3A%5CE3toE1Feed.txt%22%20%7C%20Set-MsolUserLicense%20-UserPrincipalName%20%24_.UserPrincipalName%20-AddLicenses%20%22mydomain%3ASTANDARDPACK%22%3C%2FP%3E%3CP%3Ebut...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20get%20this%20Error%3A%3C%2FP%3E%3CP%3ESet-MsolUserLicense%20%3A%20Cannot%20bind%20argument%20to%20parameter%20'UserPrincipalName'%20because%20it%20is%20null.%3CBR%20%2F%3EAt%20line%3A1%20char%3A81%3CBR%20%2F%3E%2B%20...%20%7C%20Set-MsolUserLicense%20-UserPrincipalName%20%24_.UserPrincipalName%20-AddLic%20...%3CBR%20%2F%3E%2B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20~~~~~~~~~~~~~~~~~~~~%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2B%20CategoryInfo%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3A%20InvalidData%3A%20(%3A)%20%5BSet-MsolUserLicense%5D%2C%20ParameterBindingValidationException%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2B%20FullyQualifiedErrorId%20%3A%20ParameterArgumentValidationErrorNullNotAllowed%2CMicrosoft.Online.Administration.Automatio%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20n.SetUserLicense%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnybody%20what%20I'm%20doing%20wrong%3F%20or%20a%20better%20method%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-283119%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ELicense%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-286593%22%20slang%3D%22en-US%22%3ERe%3A%20How%20do%20i%20powershell%20several%20licenses%20from%20E3%20to%20E1%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-286593%22%20slang%3D%22en-US%22%3E%3CP%3EMy%20fix%20was%20this%3A%3C%2FP%3E%3CP%3E%23Converts%20the%20Content%20of%20CSV%20file%20from%20E3%20to%20E1%20License%3CBR%20%2F%3E%23%3CBR%20%2F%3E%23Set%20Variable%20for%20What%20is%20Old%20and%20What%20is%20New%3CBR%20%2F%3E%24oldLicense%20%3D%20%22yourdomain%3AENTERPRISEPACK%22%3CBR%20%2F%3E%24newLicense%20%3D%20%22yourdomain%3ASTANDARDPACK%22%3C%2FP%3E%3CP%3E%23Define%20source%20to%20work%20with%3CBR%20%2F%3E%24users%20%3D%20import-csv%20.%5CE3toE1Group3.csv%3C%2FP%3E%3CP%3E%23Process%20each%20Account%20in%20import%20file%3CBR%20%2F%3Eforeach%20(%24user%20in%20%24users)%20%7BSet-MsolUserLicense%20-UserPrincipalName%20%24users.userprincipalname%20-AddLicenses%20%24newLicense%20-RemoveLicenses%20%24oldLicense%26nbsp%3B%20%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-285107%22%20slang%3D%22en-US%22%3ERe%3A%20How%20do%20i%20powershell%20several%20licenses%20from%20E3%20to%20E1%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-285107%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20could%20use%20Group%20Based%20licensing%20see%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Factive-directory%2Ffundamentals%2Factive-directory-licensing-whatis-azure-portal%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Factive-directory%2Ffundamentals%2Factive-directory-licensing-whatis-azure-portal%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-283282%22%20slang%3D%22en-US%22%3ERe%3A%20How%20do%20i%20powershell%20several%20licenses%20from%20E3%20to%20E1%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-283282%22%20slang%3D%22en-US%22%3E%3CP%3EThere%20are%20multiple%20scripts%20out%20there%20that%20you%20can%20just%20reuse%2C%20this%20one%20will%20make%20the%20switch%20while%20preserving%20the%20status%20of%20any%20individually%20enabled%2Fdisabled%20services%3A%20%3CA%20href%3D%22https%3A%2F%2Fblogs.technet.microsoft.com%2Fcloudpfe%2F2014%2F01%2F30%2Fhow-to-change-office-365-licenses-in-bulk-respecting-the-license-options%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fblogs.technet.microsoft.com%2Fcloudpfe%2F2014%2F01%2F30%2Fhow-to-change-office-365-licenses-in-bulk-respecting-the-license-options%2F%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-283267%22%20slang%3D%22en-US%22%3ERe%3A%20How%20do%20i%20powershell%20several%20licenses%20from%20E3%20to%20E1%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-283267%22%20slang%3D%22en-US%22%3E%3CP%3EYou'll%20probably%20just%20have%20to%20use%20foreach.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESomething%20like%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGet-Content%20%22D%3A%5CE3toE1Feed.txt%22%20%7C%20%25%20%7B%20Set-MsolUserLicense%20-UserPrincipalName%20%24_%20-AddLicenses%20%22mydomain%3ASTANDARDPACK%22%20%7D%3C%2FP%3E%3CHR%20%2F%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fquadro.tech%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EQuadrotech%3C%2FA%3E%20-%20%3CA%20href%3D%22https%3A%2F%2Fquadro.tech%2Fautopilot%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EManagement%3C%2FA%3E%2C%20%3CA%20href%3D%22https%3A%2F%2Fquadro.tech%2Freporting%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EReporting%3C%2FA%3E%20and%20%3CA%20href%3D%22https%3A%2F%2Fquadro.tech%2Fmigration%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EMigration%3C%2FA%3E%20for%20Office%20365%20and%20Exchange%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-283127%22%20slang%3D%22en-US%22%3ERe%3A%20How%20do%20i%20powershell%20several%20licenses%20from%20E3%20to%20E1%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-283127%22%20slang%3D%22en-US%22%3EYou%20have%20to%20use%20a%20csv%20file%20instead%20and%20then%20use%20a%20%E2%80%9Cfor%20each%E2%80%9D%20for%20each%20row%20in%20the%20csv%3A%3CBR%20%2F%3E%3CBR%20%2F%3ESee%3A%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fgallery.technet.microsoft.com%2Foffice%2FBulk-license-assignment-to-ef16531b%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgallery.technet.microsoft.com%2Foffice%2FBulk-license-assignment-to-ef16531b%3C%2FA%3E%3C%2FLINGO-BODY%3E
Highlighted
Contributor

We are changing several accounts from E3 to E1 and I need a Method to automate this.

My thought is to create a Text file with the Account names like Waldo@mydomain.com and name it E3toE1Feed.txt

Then Run:

Get-Content "D:\E3toE1Feed.txt" | Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -AddLicenses "mydomain:STANDARDPACK"

but...

 

I get this Error:

Set-MsolUserLicense : Cannot bind argument to parameter 'UserPrincipalName' because it is null.
At line:1 char:81
+ ... | Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -AddLic ...
+                                              ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Set-MsolUserLicense], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Online.Administration.Automatio
   n.SetUserLicense

 

Anybody what I'm doing wrong? or a better method?

 

5 Replies
Highlighted
You have to use a csv file instead and then use a “for each” for each row in the csv:

See:
https://gallery.technet.microsoft.com/office/Bulk-license-assignment-to-ef16531b
Highlighted

You'll probably just have to use foreach.

 

Something like:

 

Get-Content "D:\E3toE1Feed.txt" | % { Set-MsolUserLicense -UserPrincipalName $_ -AddLicenses "mydomain:STANDARDPACK" }


Quadrotech - Management, Reporting and Migration for Office 365 and Exchange

Highlighted

There are multiple scripts out there that you can just reuse, this one will make the switch while preserving the status of any individually enabled/disabled services: https://blogs.technet.microsoft.com/cloudpfe/2014/01/30/how-to-change-office-365-licenses-in-bulk-re...

Highlighted
Highlighted

My fix was this:

#Converts the Content of CSV file from E3 to E1 License
#
#Set Variable for What is Old and What is New
$oldLicense = "yourdomain:ENTERPRISEPACK"
$newLicense = "yourdomain:STANDARDPACK"

#Define source to work with
$users = import-csv .\E3toE1Group3.csv

#Process each Account in import file
foreach ($user in $users) {Set-MsolUserLicense -UserPrincipalName $users.userprincipalname -AddLicenses $newLicense -RemoveLicenses $oldLicense  }