Hi.
This may be a long shot, but I am running into a weird issue. I have a powershell script, that basically creates a webrequest to https://[tenant].sharepoint.com/_api/contextinfo to get the FormDigestValue, that I use to make another webrequest towards the "/_layouts/groupstatus.aspx" page.
Now, this works perfectly, when running it locally, but when I run the script in an Azure Powershell Runbook, then it fails in the first webrequest, and gives me a 401 unauthorized.
I've tried different stuff, and the closest I could get to replicating it locally, was when I change the SharePointOnlineCredentials out with a normal PSCredentials.
The script is as follows:
Add-Type –Path "[pathtofiles]\Microsoft.SharePoint.Client.dll"
Add-Type –Path "[pathtofiles]\Microsoft.SharePoint.Client.Runtime.dll"
$Username = "***********"
$Password = "***********"
$pass = ConvertTo-SecureString $Password -AsPlainText -Force
$spcreds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $pass)
$request = [System.Net.WebRequest]::Create("https://[tenant].sharepoint.com/_api/contextinfo/")
$request.Credentials = $spcreds
$request.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f")
$request.Accept = "application/json;odata=verbose"
$request.Method="Post"
$request.ContentLength = 0
$response = $request.GetResponse()
I can't wrap my head around what the issue is. My thought is it boils down to the credential part. I have made sure that the dll's are present and the most current dll's from Microsoft.
Any suggestions or thoughts are mighty appreciated.
Best Regards,
Uffe