January 1, 2012 at 12:00 am #6417MemberPoints: 0Rank: Member
by SharePointGeek at 2013-03-06 12:04:38
I'm using the below code in a MOSS 2007 (PowerShell 2.0) environment where I'm attempting to copy/rename a group files from a MOSS 2007 site/subsite to a network fileshare. The copy/rename portion seems to work fine, but all files on the destination fileshare report 0kb. Below is the code and the exception that's being captured. Any thoughts?
#$ErrorActionPreference = "SilentlyContinue"
$Url = "https://spsvcs/"
$UrlSub = "cmms"
$FullPath = $Url + $UrlSub
$destinationFolder = "c:\eam\multi\"
#$destinationFolder = "\\hsypofila002\strsSTG\Sharepoint\m"
$sourceCsv = "c:\eam\multi.CSV"
#$sourceCsv = "c:\eam\wave2.CSV"
$Site = New-Object -TypeName Microsoft.SharePoint.SPSite $Url
$web = $Site.OpenWeb($UrlSub)
$fileObjects = Import-CSV $sourceCsv
ForEach ($fileObject in $fileObjects )
$fileUrl = $fileObject.DOC_FILENAME.replace($Url,"")
$file = $web.GetFile($fileUrl)
$binary = $file.OpenBinary()
$dateTimeStamp = Get-Date -format s
$newFileName = $fileObject.DocumentType + "_" + $fileObject.SAPObjectNumber + "_" + $dateTimeStamp.replace(":","").replace("-","").replace("T","")
$extension = [System.IO.Path]::GetExtension($file.Name)
Exception calling "OpenBinary" with "0" argument(s): "There is no Web named "/cmms"."
At C:\eam\Export.ps1:20 char:35
+ $binary = $file.OpenBinary < <<< ()
+ CategoryInfo : NotSpecified: (:) , MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
by AlexBrassington at 2013-03-06 22:52:44
I'm not up to speed on 2007 and PowerShell but reading the script it appears that if it weren't to find a document it'll just create one anyway.
Step through the code for a single file and see if the $file object actually exists. Or run it with Strict Mode on.
If you're just after a simple download have you tried turning accessing the content using the UNC path approach? i.e. http://sharepoint/site/library becomes \\sharepoint\site\library
The topic ‘Calling a site/subsite’ is closed to new replies.