Invoke-WebRequest Authentication with SharePoint Online

Copper Contributor

How do you authenticate with SharePoint Online with Invoke-WebRequest? I have tried following which returns status 200, OK but it doesn't mean login was successful. I would like to list all URLs from a site. the $response.Links doesn't return anything.

 

 

try
{
    $response = Invoke-WebRequest -Uri "https://xxx365.sharepoint.com" -Credential (Get-Credential) -ErrorAction Stop
    # This will only execute if the Invoke-WebRequest is successful.
    $StatusCode = $Response.StatusCode
    $response
}
catch
{
    $StatusCode = $_.Exception.Response.StatusCode.value__
}
$StatusCode

 

 

1 Reply
Hi, did you manage to find a solution? I am experiencing the same issue.