5

How it is possible to download xml file out of this feed (website) using PowerShell?

I can authenticate with sharepoint using CSOM but do not what to do next. As service user is not administrator I cannot use "SPOService".

This script works OK for standard website, but not for Sharepoint.

$doc = New-Object System.Xml.XmlDocument
$doc.Load("http://www.{company}/feed/")
$doc.save("C:\temp\feed.xml")

I am getting this error when using for company Sharepoint:

"The remote server returned an error: (403) Forbidden."

Thanks for your time considering this question.

3

The error:

The remote server returned an error: (403) Forbidden.

occurs since authentication is required for this operation in SharePoint Online. You could utilize SharePointOnlineCredentials class from CSOM API for that purpose.

The following example demonstrates how to download RSS feed from SharePoint Online and save it into file.

Complete example

Prerequisites: SharePoint Online Client Components SDK

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")


Function Get-SPOCredentials([string]$UserName,[string]$Password)
{
    $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
    return New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
}

Function Download-Content([string]$Url,[System.Net.ICredentials]$Credentials)
{
    $client = New-Object System.Net.WebClient
    $client.Credentials = $Credentials
    $client.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f")
    $content = $client.DownloadString($url)
    $client.Dispose()
    return $content
}



$UserName = "username@contoso.onmicrosoft.com"
$Password = Read-Host -Prompt "Enter the password"    
$WebUrl = "https://contoso.sharepoint.com"
$ListId = "{65CDF954-5169-47B6-9014-0151D2083821}"
#Retrieve List RSS
$listRssUrl = "$WebUrl/_layouts/15/listfeed.aspx?List=$ListId"
$credentials = Get-SPOCredentials -UserName $UserName -Password $Password
[xml]$rss = Download-Content -Url $listRssUrl  -Credentials $credentials
#save
$rss.save("c:\temp\feed.xml")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.