Invoke-webrequest RRS feed

  • Question

  • Hi All,

    I am executing the powershell script Invoke-webrequest for few sharepoint sites.

    Among 10 SharePoint sites, 1 sharePoint site gave the output as status code "200" and status description "ok". This is a separate webapplication than the others.

    But in other SharePoint sites, the output is "401 - Unauthorized"

    However when I added "usedefaultcredentials" i.e the script becomes   Invoke-webrequest -usedefaultcredentials, then all the 9 sharePoints are giving output as "ok".

    Please let me know why it happens for these 9 sites. how should I make them run successfully giving status code "200" without using "usedefaultcredentials".


    Tuesday, July 7, 2020 6:59 AM

All replies

  • Hi,

    This may relate to your site authentication, if one site allow anonymous access, you could access the site without credential.

    If the sites are using default windows authentication, you need the default credential(the user login the server) to access your site.

    Best Regards,


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

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Wednesday, July 8, 2020 3:15 AM
  • Hi Lee,

    Actually the same site is giving 2 different status codes when invoked as webrequest in Powershell. However when I am accessing the site from browser, its asking for the credential.

    I am running the below script for the same URL and intermittently it is giving status  as "401 Unauthorized" and also sometimes returning as "200 - Ok":

    Invoke-webrequest <SiteURL>

    Can you please help me with the reason of this intermittent issue for the same site.

    Friday, July 31, 2020 2:34 PM
  • Hi B.Paul,

    As the forum will be locked on 8/10/2020, to help you better, I have created a new thread on Microsoft Q&A platform for your question. If you have any issues about this question, welcome to post it on the Q&A thread.


    Best Regards

    "SharePoint" forums will be migrating to a new home on Microsoft Q&A !
    We invite you to post new questions in the "SharePoint" forums' new home on Microsoft Q&A !

    Monday, August 10, 2020 7:14 AM