In Local Desktop,Management shell gives error 'Invoke-WebRequest : The remote server returned an error: (401) Unauthorized' RRS feed

  • Question

  • HI 

    I download the SharePoint Online management shell in my desktop and try to connect the Office 365 site.

    But i am unable to connect to the site. Please let me know why i am not connect to online site.

    Tried Script :

     $username = "your domain/username"
            $password = ConvertTo-SecureString "your password" -AsPlainText -Force
            $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
            Invoke-WebRequest -Credential $cred -Uri http://spurl

    • Edited by sudhir muvva Wednesday, July 11, 2018 1:25 PM added
    Wednesday, July 11, 2018 11:32 AM

All replies

  • Hi sudhir,

    Please make sure the user is a global administrator in your tenant.

    The following shell command for your reference:

    $userCredential = Get-Credential -UserName $adminUPN -Message "*****"
    Connect-SPOService -Url https://$ -Credential $userCredential



    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Thursday, July 12, 2018 7:17 AM
  • I have Full control permission and part of Owners i run the power shell script from local PC?
    Thursday, August 9, 2018 6:00 AM