How to Upload Files to a SharePoint Document Library Using PowerShell Script

Posted By Posted by: EPM Partners on May 21, 2013

# create the Variable Path and Pass the source folder path

$path = “D:\Source File\”;

# create the Variable destination and pass the URL of the SharePoint List

$destination = “http://projectserver14:99/PWA/SharePointListURL/“;

# Store the current user default credentials in the Variable Credentials

$credentials = [System.Net.CredentialCache]::DefaultCredentials;

# Create the object of the Webclient

$webclient = New-Object System.Net.WebClient;

# Pass the user credentials

$webclient.Credentials = $credentials; Get-ChildItem

# “For Each” loop will upload all of the files one by one onto the destination using the UploadFile method

Get-ChildItem $path | ForEach-Object { $webclient.UploadFile($destination + “/” + $_.Name, “PUT”, $_.FullName)};

Note: User need to have an access to the SharePoint list to upload the documents.


Blog Posted In Blog Posted In: How to, SharePoint
Blog Posted In Comments Off on How to Upload Files to a SharePoint Document Library Using PowerShell Script