Forum Discussion

Joe Fedorowicz's avatar
Joe Fedorowicz
Iron Contributor
Sep 23, 2016

Trying to use PowerShell for SharePoint Online, failing miserably

Hey,

 

 

I'm usually good enough to feel my way through any problem I might have, but I have hit a stopping point with PowerShell. Every time I try to pull data or execute anything, I get an "Unauthorized" error. 

 

Two questions:

 

1) Can someone send me a simple command (soup to nuts please) that will pull all the lists of a site collection. This isn't what I'm trying to do, but it will allow me to test my setup. 

 

2) What could possibly be wrong with my PowerShell? I've turned LegacyAuth on and off with Set-SPOTenant, to no avail. 

 

Thanks.

18 Replies

  • Anonymous's avatar
    Anonymous
    Do you run the Commands under the administrator account?
  • Suzanne Hunt's avatar
    Suzanne Hunt
    Brass Contributor

    Hey Joe,

    When you use connect-sponline what URL are you using? In the error it would appear you are connecting to https://harmelinmedia.sharepoint.com/...can you try to connect to https://harmelinmedia-admin.sharepoint.com/? The connect-sponline needs to connect to the admin site...Sorry if you have tried this, just trying to eliminate the simple things for you

    Suzanne

    • Joe Fedorowicz's avatar
      Joe Fedorowicz
      Iron Contributor

      I think this is 100% what I'm doing wrong. i'll update tomororw. Thanks. 

      • Vipin Tyagi's avatar
        Vipin Tyagi
        Brass Contributor

        Hey,

        A simple tip for you.

        If you are using PnP PowerShell then you can use below cmdlet to connects SPO

        1.Connect-SPOnline(site Url will be https:\\abc.sharepoint.com)

         

        But if you are using SharePoint Online Management Shell,you have only one option to connect

        1.Connect-SPOService(Url will be https:\\abc-admin.sharepoint.com)

         

        Cheers!!!!

  • Get-SPOSite executed in the SharePoint Online Management Shell should give you the list of site collections and it should work with no problems
    • Joe Fedorowicz's avatar
      Joe Fedorowicz
      Iron Contributor

      So Get-SPOSite works fine. It's anything beyond that which doesnt work.

    • Joe Fedorowicz's avatar
      Joe Fedorowicz
      Iron Contributor

      Hey, 

       

      Thanks for helping out. 

       

      1) I am a global tenant admin.

      2) I am, at least according to the download page.

       

      I want to use PnP, even though it wont do what I need done by default (editing the "required" value of a content type column). However, when I try to use Connect-SPOnline, I get the below error:

       

      Connect-SPOnline : Cannot contact web site 'https://harmelinmedia.sharepoint.com/' or the web site does not support
      SharePoint Online credentials. The response status code is 'Unauthorized'. The response headers are
      'X-SharePointHealthScore=0, SPRequestGuid=589ea69d-30b4-2000-15bb-d994b5063a31,
      request-id=589ea69d-30b4-2000-15bb-d994b5063a31, X-MSDAVEXT_Error=917656; Access+denied.+Before+opening+files+in+this+l
      ocation%2c+you+must+first+browse+to+the+web+site+and+select+the+option+to+login+automatically.,
      MicrosoftSharePointTeamServices=16.0.0.5715, X-Content-Type-Options=nosniff, X-MS-InvokeApp=1; RequireReadOnly,
      Content-Length=0, Content-Type=text/plain; charset=utf-8, Date=Fri, 23 Sep 2016 15:45:04 GMT, P3P=CP="ALL IND DSP COR
      ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI", Server=Microsoft-IIS/8.5,
      X-Powered-By=ASP.NET'.
      At line:1 char:1
      + Connect-SPOnline -Url https://harmelinmedia.sharepoint.com/ -Credenti ...
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : NotSpecified: (:) [Connect-SPOnline], NotSupportedException
          + FullyQualifiedErrorId : System.NotSupportedException,SharePointPnP.PowerShell.Commands.Base.ConnectSPOnline

       

      • Dean_Gross's avatar
        Dean_Gross
        Silver Contributor
        That looks like a problem with your credentials, double check your values against the instructions in the Getting Started section of https://github.com/OfficeDev/PnP-PowerShell.
        If you have MFA, you need to use the UseWebLogin parameter in the connect-sponline statement

Resources