function LoadSharePointPowerShellEnviroment
{
write-host
write-host "Setting up Powershell enviroment for Sharepoint" -foregroundcolor Magenta
Add-PSSnapin "Microsoft.Sharepoint.PowerShell" -ErrorAction SilentlyContinue
Write-host "Sharepoint PowerShell Snapin loaded." -foregroundcolor Green
}
Clear-Host
LoadSharePointPowerShellEnviroment
write-host
Clear-Host
# Set the variables
$WebURL = "https://stiteCollection/sites/Marks"
$DocLibName = "SiteAssets"
$FilePath = "C:\Users\SPDevFAdmin\Documents\Scripts\AppLoader.js"
$web = Get-SPWeb $WebURL
$List = $web.GetFolder($DocLibName)
$Files = $List.Files
# Get just the name of the file from the whole path
$FileName = $FilePath.Substring($FilePath.LastIndexOf("\")+1)
# Load the file into a variable
$File= Get-ChildItem $FilePath
Write-Host "uploading file $File " -ForegroundColor Yellow
$stream = $file.OpenRead()
# Upload it to SharePoint
$done = $Files.Add($DocLibName +"/" + $FileName, $stream,$true)
Write-Host "$done has been uploaded" -ForegroundColor Magenta
if($stream){
Write-Host "dispose stream" -ForegroundColor Yellow
$stream.Dispose()
}
if($web -ne $null){
Write-Host "dispose web" -ForegroundColor Yellow
$web.Dispose();
}