Question

First post here.. I have a small issue with a PowerShell command. I'm using the Azure AD module and trying to bulk enable users for O365 using a CSV file and this guide: http://www.powershellmagazine.com/2012/04/23/provisioning-and-licensing-office-365-accounts-with-powershell/

I've gotten all the way through without issues and can enable a single user using the method outlined in that article, but when trying to bulk enable I get the following:

Command:

Import-CSV -Path sapusers_sample.csv | ForEach-Object {Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -AddLicenses wcs1:STANDARDWOFFPACK -LicenseOptions $options}

Error:

Set-MsolUserLicense : You must provide a required property: Parameter name: UsageLocation

($options is just a variable containing the disabled plans, we don't want users to have Exchange enabled just yet)

The weird thing is, when reading the help text for Set-MsolUserLicense, there is no UsageLocation parameter listed. And when I try to add it, for instance Set-MsolUserLicense -UsageLocation US, PS returns the following:

Set-MsolUserLicense : A parameter cannot be found that matches parameter name 'UsageLocation'

So... is PS asking for a parameter for Set-MsolUserLicense that doesn't exist?.. or am I misinterpreting this.. any help is appreciated - thanks!!!!

Dave

Was it helpful?

Solution

Office 365 requires the user's usage location to determine which service are available to them. Thus, UsageLocation is a property of a user, which can be set with the -UsageLocation parameter of Set-MsolUser or New-MsolUser:

 Set-MsolUser -UserPrincipalName bob@contoso.com -UsageLocation "US";

Once you've set the user's UserLocation, you should be able to assign licenses to that user.

If the usage location is the same for all your users, you can include it directly in you ForEach-Object loop:

Import-CSV -Path sapusers_sample.csv | ForEach-Object {
    Set-MsolUser -UserPrincipalName $_.UserPrincipalName `
        -UsageLocation "US";
    Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName `
        -AddLicenses wcs1:STANDARDWOFFPACK `
        -LicenseOptions $options;
}

You could also just as easily add a "UsageLocation" column to the input CSV:

Import-CSV -Path sapusers_sample.csv | ForEach-Object {
    Set-MsolUser -UserPrincipalName $_.UserPrincipalName `
        -UsageLocation $_.UsageLocation;
    Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName `
        -AddLicenses wcs1:STANDARDWOFFPACK `
        -LicenseOptions $options;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top