2011-08-26 9 views
0

我一直對這個代碼獲得以下錯誤:PowerShell的爲SharePoint >>讓我們RD錯誤

#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 
+3

錯誤是很明顯? '$ web'未知。你的意思是有'$ webUrl'? – manojlds

+0

@Manojlds:可能你是對的。我會再試一次...謝謝。 –

+0

[我是否正確編寫這個powershell?因爲它沒有做我想要的東西](http://stackoverflow.com/questions/7208375/am-i-coding-this-powershell-correctly-because-it-does-not-do-what-i-tended) –

回答

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-- 
} 
相關問題