Monday, March 09, 2015

Upload files to library

Simple script to upload all files from specific folder to documentlibrary.

 

$path = "C:\myfiles\TestDocs";

$user = "mydomain\john.doe"

$pass= "mysecretpassword"

$destination = "https://mysite.mycompany.com/mylib";

 

 

$securePasssword = ConvertTo-SecureString $pass -AsPlainText -Force;

$credentials = New-Object System.Management.Automation.PSCredential ($user, $securePasssword);

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

 

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

$webclient.Credentials = $credentials;

 

Get-ChildItem $path | Where-Object {$_.Length -gt 0} | ForEach-Object { $webclient.UploadFile($destination + "/" + $_.Name, "PUT", $_.FullName)};

 

No comments: