Add files in a Folder to a Document Library using PowerShell
Below Powershell Script will upload the files in your Local Drive to SharePoint Document library.
Here i am Uploading to Library named Documents from D drive ,
asnp "*sh*"
$url=Read-Host "Enter
Site Url"
$web=Get-SPWeb -Identity
$url
if($web)
{
try
{
$list = $web.Lists.TryGetList("Documents")
$files
= Get-ChildItem
-Path "D:\Manju"
-Force -Recurse
foreach
($file in
$files)
{
$stream
= $file.OpenRead()
$done= $list.RootFolder.Files.Add($file.Name, $stream, $true)
Write-Host
$done.Name "Uploaded
into the Site" -BackgroundColor Green
}
}
catch
{
$ErrorMessage
= $_.Exception.Message
Write-Host $ErrorMessage -BackgroundColor Yellow
}
}
else
{
Write-Host "Site Doesn't exist"
}
$list.Update();
