I'm looking to build a Powershell script that does the following to all documents in a SharePoint 2010 document library:
- Downloads the document to a network file share
- Deletes the original document in the document library
I started experimenting with the following:
$Url = "http://sharepoint2010/myweb/Shared%20Documents/aaa.txt"
$Path = "C:\test\aaa.txt"
$Username = ""
$Password = ""
$WebClient = New-Object System.Net.WebClient
$WebClient.Credentials = New-Object System.Net.Networkcredential($Username, $Password)
$WebClient.DownloadFile( $url, $path )
However I get "(401) Unauthorized" exceptions even if I execute this on the SharePoint server. Note that this script will execute on a schedule running on a SharePoint WFE server.