none
Set-Msoluser : Access Denied. You do not have permissions to call this cmdlet RRS feed

  • Question

  • I have successfully connected to Office 365 Admin service and Exchange Online Services. I have tested the cmdlets such as Get-MsolUser and they work fine. However, when I try to run the command Set-MsolUser to change the Title, I get the Access Denied error as shown below. It's weird because I can manually go into Exchange and change any property I want but it won't let me run this command? Any way around this?

    Script to update Office 365 user attributes

    ## Variables
    $systemmessagecolor = "cyan"
    $processmessagecolor = "green"
    $savedcreds=$false                      ## false = manually enter creds, True = from file
    $credpath = "c:\downloads\tenant.xml"   ## local file with credentials if required
    
    ## If you have running scripts that don't have a certificate, run this command once to disable that level of security
    ## set-executionpolicy -executionpolicy bypass -scope currentuser -force
    
    Clear-Host
    
    write-host -foregroundcolor $systemmessagecolor "Script started`n"
    
    #install-module msonline
    Import-Module -Name "C:\Temp\MsOnline" -Verbose
    write-host -foregroundcolor green "MSOnline module loaded"
    
    ## Get tenant login credentials
    $cred = Get-Credential
    
    
    ## Connect to Office 365 admin service
    connect-msolservice -credential $cred
    write-host -foregroundcolor $systemmessagecolor "Now connected to Office 365 Admin service"
    
    ## Start Exchange Online session
    $EXOSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell -Credential $cred -Authentication Basic -AllowRedirection
    import-PSSession $EXOSession -AllowClobber
    write-host -foregroundcolor $processmessagecolor "Now connected to Exchange Online services`n"
    write-host -foregroundcolor $systemmessagecolor "Script Completed`n"
    
    
    # Load data from file.csv
    $EXUsers = Import-csv file_path.csv
    
    
    # Count variable for number of users update
    $count = 0
    
    # Go through each row that has user data in the CSV we just imported 
    ForEach($User in $EXUsers)
    {
        # Ppopulate hash table for Get-Msoluser splatting:
        $GetParams =
        @{
            UserPrincipalName     = $User.userPrincipalName
        }
    
        # Initialize hash table for Set-Msoluser splatting:
        $SetParams =
        @{
            UserPrincipalName     = $User.userPrincipalName
            Title                 = $User.title
        }
    
        # Get user and update.
        if ( Get-Msoluser @GetParams)
        {
             # Set User attributes
             Set-MsolUser @SetParams
    
             # Print that the user was updated 
             Write-Host -ForegroundColor Yellow "$User - User attributes have been updated." 
    
             # Update Count
             $count += 1    
         }
    }
    
    # Print the number of updated users
    Write-Host $count "Users have been updated" -ForegroundColor Green

    Error message

    Set-Msoluser : Access Denied. You do not have permissions to call this cmdlet.
    At line:1 char:59
    + ... ncipalName "name@company.com" | Set-Msoluser -Title "Test Title"
    +                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : OperationStopped: (:) [Set-MsolUser], MicrosoftOnlineException
        + FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.AccessDeniedException,Microsoft.Online.Administration.Automation.SetUser

    Wednesday, June 24, 2020 8:00 PM

All replies

  • The error is explicit and cannot be fixed with a script.

    "Access Denied. You do not have permissions to call this cmdlet."

    YOU must obtain permissions to use the CmdLet from you portal admin.



    \_(ツ)_/

    Wednesday, June 24, 2020 9:16 PM
    Moderator
  • I should have the full permission. I can go into exchange and edit but can't edit with the script? Weird.
    Wednesday, June 24, 2020 9:44 PM
  • You have to have unrestricted access to the PowerShell CmdLets.  The connection is restricted per CmdLet.  Be sure you have admin access and are using MFA to authenticate.

    For this kind of issue you should post in the Exchange Online forum.  They will be best at helping you with the current Exchange requirements and limits.


    \_(ツ)_/


    Wednesday, June 24, 2020 9:57 PM
    Moderator
  • Hi,
    Was your issue resolved? 
    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
    If no, please reply and tell us the current situation in order to provide further help.
    Best Regards,
    Yang Yang

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, July 3, 2020 5:46 AM