2011-08-26 53 views
1

需要從名爲「Region」的字段名稱中找出文檔集名稱。我需要將文檔集名稱設置爲任何區域(NW,SW,NE,SE等),並將文件從文檔庫的根目錄移動到其受尊重的文檔集。我不介意硬編碼的網站或網址和文件lib網址。我正在創建此錯誤:我是否正確地編寫了這個powershell?因爲它沒有做我想要的東西

','後缺少表達式。在C:\ PS \ MoveFiles.ps1:13 char:59 + $ list.Items.MoveTo($ destinationFolderUrl + $ file.Name,< < < < true); + CategoryInfo:ParserError:(,:字符串)[],ParseException的+ FullyQualifiedErrorId:MissingExpressionAfterToken

#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) 
      { 
       $docset=$($file.Region); 
       $destinationFolderUrl = "http://CiscoIntranet/sites/VOIP/ForwardTech/" + $docset; 
       $list.Items.MoveTo($destinationFolderUrl + $file.Name, true); 
       $webUrl.Update(); 
      } 
} 
+0

什麼是代碼的實際效果? – JNK

+0

什麼是錯誤? –

+0

','後缺少表達式。 在C:\ PS \ MoveFiles.ps1:13 char:59 + $ list.Items.MoveTo($ destinationFolderUrl + $ file.Name,<<<< true); + CategoryInfo:ParserError:(,:String)[],ParseException + FullyQualifiedErrorId:MissingExpressionAfterToken –

回答

0

這是工作的代碼

$siteURL="http://Server" 
$docLib = "My Doc Lib" 
$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-- 
} 
5

第二個參數應該是$true而不僅僅是真正的。

我複製的相同的錯誤如下:

function fun($m,[bool]$f) { 
     write-host $m $f 
} 

fun ("blah", true) 

古怪,類似:

function fun([bool]$f) { 
     write-host $m $f 
} 
fun (true) 

給出如下錯誤:

fun : Cannot process argument transformation on parameter 'f'. Cannot convert value "System.Management.Automation.PSCustomObject" to type "System.Boolean", parameters of this type only accept booleans or numbers, use $true, $false, 1 or 0 instead.

這是更具描述性的,並將該溶液在錯誤信息中!

+0

+1 - 我懷疑但沒有動機測試:) – JNK

+0

Manojlds:讓我試試你的解決方案 –

+0

得到這個錯誤。您無法在空值表達式上調用方法。 在C:\ PS \ MoveFiles.ps1:8 char:28 + $ folder = $ web.GetFolder <<<<($ folderUrl) + CategoryInfo:InvalidOperation:(GetFolder:String)[],RuntimeException + FullyQualifiedErrorId :InvokeMethodOnNull 方法調用失敗,因爲[Microsoft.SharePoint.SPListItemCollection]不包含名爲'MoveTo'的方法。 在C:\ PS \ MoveFiles.ps1:13 char:23 + $ list.Items.MoveTo <<<<($ destinationFolderUrl + $ file.Name,$ true); + CategoryInfo:InvalidOperation :(MoveTo:String) –

相關問題