I keep getting following error. The code looks good but I guess it's not grabing the siteUrl to create a full url.
PS C:\sales> .\Import.ps1 Exception calling "Add" with "3" argument(s): "The URL 'Sales_Records/salesreport.pdf' is invalid. It may refer to a non existent file or folder, or refer to a valid file or folder that is not in the current Web." At C:\sales\Import.ps1:32 char:37 + $temp = $templateFolder.files.Add <<<< ($targetUrl,$stream,$true) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException
PS C:\Powershell>
= = = here is the code = = =
Add-PSSnapin Microsoft.SharePoint.PowerShell
$SiteUrl = "http://portal.GrandParkway.com/Sales"
$web = Get-SPWeb $SiteUrl
$Library = "Sales_Records" #Internal Name. I tried Display Name but same error
$docLibrary = $web.Lists[$Library]
$rootFolder = $docLibrary.RootFolder
$templateFolder = $web.GetFolder("Sales Records")
$path = "c:\\sourcefile"
$Filename = "salesreport.pdf"
$filewithPath = $path + "\" + $filename
$strPathInfo = Get-Location
$stream = [IO.File]::OpenRead($Filewithpath)
$targetUrl = $SiteUrl+"/$Library/"+$Filename.Replace(" ","")
$temp = $templateFolder.files.Add($targetUrl,$stream,$true)
$stream.close()
$web.Dispose()