Following small script will upload file to a given document library in SharePoint
- $webUrl = "https://sp13/sites/site"
- $docLibName = "SiteLog"
- $filePath = "C:\Logs\test.txt"
- #upload file
- $web=Get-SPWeb $webUrl
- $file=Get-Item $filePath
- $fileStream=([System.IO.FileInfo](Get-Item $file.FullName)).OpenRead()
- $folder=$web.GetFolder($docLibName)
- $spFile=$folder.Files.Add($folder.Url + “/” + $file.Name, [System.IO.Stream]$fileStream, $true)
- $fileStream.Close()