lundi 15 décembre 2014

Powershell DownloadFile(,) command giving 403 - Forbidden error



I am using Powershell DownloadFile(,) command for reading a .csv file from a document library in SharePoint 2013 site. When i ran the code on my DEV environment, it ran properly. The DEV environment is using http://. But , when I run this code on TEST environment i get 403 Forbidden error. The site(TEST environment) is running over https://.


I am using below code ,



$FilePath = "https://ServerName/sites/SiteName/MyDocumentLibrary/MyCSVFile.csv"
$localPath = "C:\temp\test.csv"
$wc = New-Object System.Net.Webclient
$wc.DownloadFile($FilePath, $localPath)
$list = Import-Csv $localPath


I have gone through various articles which talks about passing credentials with the Webclient($wc) object. But, with no luck. Still getting same error.


I am still unaware, when/why does Powershell throws this error ? What is the root cause of this error?


Any help will be greatly appreciated.








0 commentaires:

Enregistrer un commentaire