Okay what I'm trying to do is combine a script running on a Schedule Task and a manual script to one Schedule Task script. Each script works by themselves.
Here is the script that runs on a task.
Get-MsolUser -UnlicensedUsersOnly -MaxResult 20000 | Where { ($_.UserPrincipalName.EndsWith(“@domain.edu”))} | Set-MsolUser -UsageLocation "US"
Get-MsolUser -UnlicensedUsersOnly -MaxResult 20000 | Where { ($_.UserPrincipalName.EndsWith(“@domain.edu”))} | Set-MsolUserLicense -AddLicenses "Packname1"
Here is the other script
$List = Import-CSV "C:\CSV Files\test.csv"
$AccountSkuId = "Packname2"
$Step1 = New-MsolLicenseOptions -AccountSkuId $AccountSkuId -DisabledPlans yammer_edu,sharepointwac_edu,sharepointstandard_edu,exchange_s_standard,mcostandard
foreach ($Users in $List)
{
Set-MsolUser -UserPrincipalName $Users.Username -UsageLocation US
Set-MsolUserLicense -UserPrincipalName $Users.Username -AddLicenses $AccountSkuId -verbose -LicenseOptions $Step1
}
Here is what I've come up with on the combine
$AccountSkuId = "Packname2"
$Step1 = New-MsolLicenseOptions -AccountSkuId $AccountSkuId -DisabledPlans yammer_edu,sharepointwac_edu,sharepointstandard_edu,exchange_s_standard,mcostandard
Get-MsolUser -UnlicensedUsersOnly -MaxResult 20000 | Where { ($_.UserPrincipalName.EndsWith(“@domain.edu”))}
foreach ($User in $Users) {
Set-MsolUser -UserPrincipalName $User UsageLocation "US"
Set-MsolUserLicense -UserPrincipalName $User -AddLicenses "Packname1"
Set-MsolUserLicense -UserPrincipalName $User -AddLicenses $AccountSkuId -verbose -LicenseOptions $Step1
}
The problem I have is that I'm not getting the user(s) found in the Get-MsolUser to the foreach loop. I know the variable are not righ in the foreach loop.
Ideas???