Powershell scripting in Office365

I have a list of users that I am attempting to reference so I can assign licenses. There is one variable that is throwing an error and I cant find the issue. Can anyone else take a whack at it and let me know what I am doing wrong?

$POWPPText = foreach ($user in $(Get-Content c:\users\user\desktop\test.txt)){Get-MsolUser $user.UserPrincipalName}

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I have an article about licensing users in my blog.  There is a script on this page you can copy and use


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Juan OcasioApplication DeveloperCommented:
What is the error being thrown?
LA_AdminAuthor Commented:
The error being thrown was "Positional Parameters not found". I chose the above option as the answer because the last part of the script showed me that my thinking was flawed in how the script should use the variable.

 foreach($user in $users){  
 set-msoluserlicense -userprincipalname $user -addlicenses AccountSkuID:XXXXXXXXX

Open in new window

I split my script up and used the above script as a guide, and I was able to run the script successfully.

Here is my sanitized script, to provide context.

# Project Online with ProjectPro users
    $POPPUsers = Get-Content c:\users\user\desktop\test.txt

# ProjectOnline with Project Pro Variable
    $ProjOnProjPro = New-MsolLicenseOptions -AccountSkuId contoso:PROJECTONLINE_PLAN_2 -DisabledPlans SHAREPOINTWAC, SHAREPOINTENTERPRISE

# ProjectOnline With Project Pro users text file
Set-MsolUserLicense -UserPrincipalName $POPPUsers -RemoveLicenses contoso:projectonline_plan_1
foreach($user in $POPPUsers){
Set-MsolUserLicense -UserPrincipalName $POPPUsers -AddLicenses contoso:ProjectOnline_Plan_2 -LicenseOptions $ProjOnProjPro

Open in new window

Thanks everyone!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.