?
Solved

O365 PowerShell "You Do Not Have Permissions"

Posted on 2016-09-07
3
Medium Priority
?
1,240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 42

Assisted Solution

by:Vasil Michev (MVP)
Vasil Michev (MVP) earned 400 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 1600 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

Ransomware Attacks Keeping You Up at Night?

Will your organization be ransomware's next victim?  The good news is that these attacks are predicable and therefore preventable. Learn more about how you can  stop a ransomware attacks before encryption takes place with our Ransomware Prevention Kit!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Suggested Courses

765 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