我正在使用这个脚本 http://get-spscripts.com/2010/10/bulk-upload-files-with-metadata-into.html 脚本
function Copy-FilestoSP
{
Param (
[parameter(Mandatory=$true)][string]$LocalPath,
[parameter(Mandatory=$true)][string]$SiteUrl,
[parameter(Mandatory=$true)][string]$Library,
[parameter(Mandatory=$false)][string]$LibraryStartFolder,
[parameter(Mandatory=$false)][string]$ManifestFilePath,
[parameter(Mandatory=$false)][switch]$IncludeSubFolders,
[parameter(Mandatory=$false)][switch]$Approve,
[parameter(Mandatory=$false)][switch]$CheckIn,
[parameter(Mandatory=$false)][switch]$Overwrite,
[parameter(Mandatory=$false)][switch]$FlattenStructure
)
try
{
#Get web and document library objects
$web = Get-SPWeb $SiteUrl
$docLibrary = $web.Lists[$Library]
---code skipped-----
当我调试时,我发现在Get-SPWeb之后我得到了
You cannot call a method on a null-valued expression.
At E:\BH\utility\Get-SPScripts.Copy-FilesToSP.ps1:331 char:21
+ $web.Dispose <<<< ()
+ CategoryInfo : InvalidOperation: (Dispose:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
在331的$ web.Dispose()
catch [System.SystemException]
{
write-host "The script has stopped because there has been an error. "$_.Message
}
finally
{
$web.Dispose()
}
}
write-host "SharePoint 2010 Multiple File Upload Script - Get-SPScripts.com"
我正在执行它
Copy-FilestoSP -LocalPath "E:\files" -SiteUrl "http://sp2010" -Library "myDocuments"