Problem with setting the user's UsageLocation attribute in Set-MsolUser cmdlet

The Azure Active Directory Sync tool (aka DirSync) already has been setup here to synchronize on-premises Active Directory users to Office 365.

Assigning license within Office 365 admin center portal for one user is quite is easy. But, I don’t have much luck with doing similar stuff through the PowerShell.

I have Microsoft Online Services Sign-In Assistant and Azure AD Module already install on my Windows 8.1 workstation. I can Connect-MsolService with my Office 365 global admin account without any problem.
 
From my understanding, before I can assign a licence to a user using  Set-MsolUserLicense cmdlet with the -AddLicenses parameter we must set the user's UsageLocation attribute.
 
I’m trying to run this command:

Set-MsolUser -UserPrincipalName user1@mydomain.onmicrosoft.com -UsageLocation US

But, PowerShell is returning an error: Set-MsolUser : Access Denied. You do not have permissions to call this cmdlet.

Any idea why and what needs to be done to fix this error?

Thanks in advance
LVL 1
OlevoAsked:
Who is Participating?

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

x
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.

Vasil Michev (MVP)Commented:
Check the credentials you are connecting with. The cmdlet is correct, and there's no way you can prevent an GA from running it afaik.
OlevoAuthor Commented:
I have tried different Office 365 global admin account, the same "Access Denied" error?! Don't have any problem login onto Office 365 web portal with that global admin account.
Vasil Michev (MVP)Commented:
Can you set the Usage location from the portal?
OlevoAuthor Commented:
Hmm..., don't have any problems with setting Usage Location when I log as O365Admin@mycompany.onmicrosoft.com but not much luck when I logged as O365Admin@mycompany.com Both accounts are Office 365 global admins. Well, I'm guessing that I have to use "onmicrosoft" from now on when I use PowerShell cmdlet's.
Vasil Michev (MVP)Commented:
This is the type of error you will get when you try to run against a user that is not in your directory. If both mycompany.com and mycompany.onmicrosoft.com are in the same tenant, you should be able to run it with either admin account.

What does

Get-MsolUserRole -UserPrincipalName O365Admin@mycompany.com

Open in new window


show?

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
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
Office 365

From novice to tech pro — start learning today.