Link to home
Start Free TrialLog in
Avatar of LA_Admin
LA_Admin

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of zulazen
zulazen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Juan Ocasio
What is the error being thrown?
Avatar of LA_Admin
LA_Admin

ASKER

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!