Link to home
Start Free TrialLog in
Avatar of Hypervizor
HypervizorFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Office 365 Batch Scripts Help

We have exported all the users out of 365 via connecting to the tenancy using the ‘Windows Azure Active Directory Module for Windows PowerShell’ and the command ‘Get-MsolUser -EnabledFilter EnabledOnly -all | Export-csv allusers.csv’ this then gives me a list of users to run commands on. I then sort the csv’s so I have one for students and staff containing a column called upn which has all the account names I wish to apply a command to.

We need help / validation with formulating the commands to assign licenses on bulk to groups of users, We believe we have this one sorted for students but it would be good if someone could validate:

$AccountSkuId = "ashfordschool:OFFICESUBSCRIPTION_STUDENT"

$UsageLocation = "GB"

$LicenseOptions = New-MsolLicenseOptions -AccountSkuId $AccountSkuId

$Users = Import-Csv c:\students.csv

$Users | ForEach-Object {

Set-MsolUser -UserPrincipalName $_.upn -UsageLocation $UsageLocation

Set-MsolUserLicense -UserPrincipalName $_.upn -AddLicenses $AccountSkuId

}

Open in new window


We have two licenses I need to assign to students, one called ‘Office 365 ProPlus for Students’ so the students can get office on their iPads and another coming I believe the A2 plan so they can get mailboxes. I assume if I just run the command twice on the student accounts under the two different license names they will be assigned the two licenses?

 Also for staff I have manually assigned my account the @my_company_name.co.uk domain and the correct staff license ‘Office 365 Education A3 for Faculty’, however when I go to sign I get a ‘Something Went Wrong’ message (see picture User generated image). I took the option ‘Exchange Online (Plan 2)’ part out of the license and could sign in OK (I guess this is because we haven’t migrated our mailboxes yet and won’t be until the next available downtime window). So my question is - I believe when assigning licenses you can assign options of which elements you want. This seems to be a little more complicated than my license script above, so we could do with some assistance with the options.

We need help with formulating the commands to assign domains to users:

We have two domains @examplea.co.uk for staff and @exampleb.co.uk for students. I need to change the domain name for these accounts from the default @examplea.onmicrosoft.com. I have the following command but it wouldn’t quite work:

$Users = Import-Csv c:\students.csv

$Users | ForEach-Object { Set-MsolUserPrincipalName -ObjectId $_.upn -NewUserPrincipalName ($_.UserPrincipalName.Split(“@”)[0] + “@exampleb.co.uk”)}

}

Open in new window


Can’t remember the exact error.

 
Also, we need help with formulating the commands to assign mailboxes to one of the two domains

Need to setup mailboxes just for the students on the exampleb.co.uk have no idea how to do this yet (the Staff are staying on our company exchange box for the time being).
ASKER CERTIFIED SOLUTION
Avatar of Vasil Michev (MVP)
Vasil Michev (MVP)
Flag of Bulgaria image

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 Hypervizor

ASKER

Thanks Vasil.