Skip to content

Instantly share code, notes, and snippets.

@mdnmdn
Created December 18, 2011 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdnmdn/1493541 to your computer and use it in GitHub Desktop.
Save mdnmdn/1493541 to your computer and use it in GitHub Desktop.
Upload file to a sharepoint doc library via powershell
$siteUrl = "http://sharepoint/"
$listName = "Site Assets"
$fileName = "OfferApp.xap"
$filePath = "OfferApp.Web\ClientBin\" + $fileName
[system.reflection.assembly]::LoadWithPartialName("Microsoft.Sharepoint")
$site = New-Object Microsoft.SharePoint.SPSite($siteUrl)
$web = $site.OpenWeb()
$list = $web.Lists[$listName]
$fileCollection = $list.RootFolder.Files
$file = Get-Item $filePath
$stream = $file.OpenRead()
$uploaded = $fileCollection.Add($file.Name, $stream, $TRUE)
"Uploaded " + $file.Name
if ($stream) {$stream.Dispose()}
#$files = get-childItem -Exclude *.ps1
#foreach ($file in $files)
#{
# $stream = $file.OpenRead()
# $uploaded = $fileCollection.Add($file.Name, $stream, $TRUE)
# "Uploaded " + $file.Name
# if ($stream) {$stream.Dispose()}
#}
if ($web) {$web.Dispose()}
if ($site) {$site.Dispose()}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment