Showing posts with label Upload file to SharePoint using PowerShell. Show all posts
Showing posts with label Upload file to SharePoint using PowerShell. Show all posts

Thursday, 15 May 2014

Upload file to SharePoint using PowerShell


$SPWebURL = “http://SP2013/sites/SiteCollA”
$MylibraryName = “MyDocumentLib”
$MyFilePath = “C:\file.docx”
$SPWeb = Get-SPWeb $SPWebURL
$List = $SPWeb.GetFolder($MylibraryName)
$Files = $List.Files
$FileName = $MyFilePath.Substring($MyFilePath.LastIndexOf("\")+1)
$File= Get-ChildItem $MyFilePath
$Files.Add($MylibraryName +"/" + $FileName,$File.OpenRead(),$false)
$SPweb.Dispose()