Solved

O365 PowerShell "You Do Not Have Permissions"

Posted on 2016-09-07
3
112 Views
Last Modified: 2016-09-09
I'm having issues running a Command in PowerShell for O365. I have done this before with the same account but I have no idea what changed or how. When connecting to Power Shell I run:

$UserCredential = Get-Credential
(This will ask me for my O365 login which I input as usual)
Connect-MsolService -Credential $UserCredential

We have a hybrid environment with multiple domain and when I try to change a users domain I run:  Set-MsolUserPrincipalName -UserPrincipalName username@domain.onmicrosoft.com  -NewUserPrincipalName username@ourdomain.org

then I get:

Set-MsolUserPrincipalName : Access Denied. You do not have permissions to call this cmdlet.
At line:1 char:1
+ Set-MsolUserPrincipalName -UserPrincipalName asdf@cplc.onmicrosoft.co ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [Set-MsolUserPrincipalName], MicrosoftOnlineException
    + FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.UserNotFoundException,Microsoft.Online.Administration.Automation.SetUserPrincipalName

Again, I have used this account before and have performed this action without any issues before. Not sure what changed or how to fix. Any help will be appreciated.
Thanks
0
Comment
Question by:menendeza
3 Comments
 
LVL 38

Assisted Solution

by:Vasil Michev (MVP)
Vasil Michev (MVP) earned 100 total points
ID: 41788195
The error messages can sometimes be misleading. You will get the exact same error if the user is not found, for example:

[17:31:00][Login script]# Set-MsolUserPrincipalName -UserPrincipalName sdfdsfds@domain.com -NewUserPrincipalName user@domain.com
Set-MsolUserPrincipalName : Access Denied. You do not have permissions to call this cmdlet.
At line:1 char:1

Open in new window


So, double-check the user, his UPN might be a custom domain, not the default onmicrosoft.com one. And of course, double-check the credentials.
0
 
LVL 16

Accepted Solution

by:
FOX earned 400 total points
ID: 41788223
Use steps in this link to connect to your EXCHANGE ONLINE SESSION. (IT HAS COMMANDS FOR SHAREPOINT AND ANOTHER SESSION AS WELL)
You probably didn't set your execution policy.

ref link: https://technet.microsoft.com/en-us/library/dn568015.aspx
0
 

Author Comment

by:menendeza
ID: 41791286
Thank you Foxluv
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
This article will help you understand what HashTables are and how to use them in PowerShell.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…
This Experts Exchange lesson shows how to use VBA to loop through rows in Excel.  In order to sort, filter, and use database features, there needs to be a value in each column for every row. When data arrives with values missing, code to copy values…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now