Powershell for SharePoint>>得到我们!错误

时间:2011-08-26 20:34:41

标签: powershell sharepoint-2010

我在这段代码上一直收到以下错误:

#Setup default variables
$webUrl = Get-SPWeb -Identity "http://CiscoIntranet/sites/VOIP"
$list = $webUrl.GetList("http://CiscoIntranet/sites/VOIP/ForwardTech")
[System.Reflection.Assembly]::LoadWithPartialName(”Microsoft.SharePoint”) 

function ProcessMove {
   param($folderUrl)
   $folder = $web.GetFolder($folderUrl)
        foreach ($file in $folder.Files)
            {
                [Microsoft.SharePoint.SPFile]$spFile = $file;           
                $docset=$($file.Counterparty2);
                $destinationFolderUrl = "http://CiscoIntranet/sites/VOIP/ForwardTech/" + $docset;               
                $spFile.MoveTo($destinationFolderUrl + $file.Name, $true);
                $webUrl.Update();
            }
}
#Move root Files
ProcessMove($list.RootFolder.Url)

You cannot call a method on a null-valued expression.
At C:\PS\MoveFiles.ps1:8 char:28
+    $folder = $web.GetFolder <<<< ($folderUrl)
    + CategoryInfo          : InvalidOperation: (GetFolder:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Method invocation failed because [Microsoft.SharePoint.SPListItemCollection] doesn't contain a method named 'MoveTo'.
At C:\PS\MoveFiles.ps1:13 char:23
+                 $list.Items.MoveTo <<<< ($destinationFolderUrl + $file.Name, $true);
    + CategoryInfo          : InvalidOperation: (MoveTo:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

1 个答案:

答案 0 :(得分:1)

这是工作代码......

$siteURL="http://CiscoIntranet/sites/VOIP"
$docLib = "ForwardTech"
$site=Get-SPSite $siteURL
$web=$site.RootWeb
$collFiles=$web.GetFolder($docLib).Files
$count=$collFiles.Count
while($count -ne 0)
{
$item = $collFiles[$count-1].Item
$DocSet = $item["Region"]
Write-Host "$DocSet is the doc set. $collFiles[$count-1].Name is name"
$collFiles[$count-1].MoveTo($siteURL + "/" + $docLib + "/" + $DocSet + "/"  + $collFiles[$count-1].Name, $true)                       
$count--
}