我是否正确编码了这个 powershell?因为它不符合我的意图 [英] Am I coding this powershell correctly? Because it does not do what I intended
问题描述
需要从名为Region"的字段名称中找出文档集名称.我需要将文档集名称设置为任何区域(NW、SW、NE、SE 等),并将文件从文档库的根目录移动到它受尊重的文档集.我不介意硬编码站点或 web url 和 doc lib url.我收到此错误:
Need to find out the document set name from a field name called "Region". I need to set the doc set name to be whatever Region is (NW, SW, NE, SE, etc.) and move files from root of the document library to it's respected doc set. I dont mind hard coding the site or web url and doc lib url. I am geting this error:
',' 后缺少表达式.在 C:\PS\MoveFiles.ps1:13 char:59 + $list.Items.MoveTo($destinationFolderUrl + $file.Name, <<<< true);+ CategoryInfo : ParserError: (,:String) [], ParseException +fullyQualifiedErrorId : MissingExpressionAfterToken
Missing expression after ','. At C:\PS\MoveFiles.ps1:13 char:59 + $list.Items.MoveTo($destinationFolderUrl + $file.Name, <<<< true); + CategoryInfo : ParserError: (,:String) [], 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();
}
}
推荐答案
这是工作代码
$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--
}
这篇关于我是否正确编码了这个 powershell?因为它不符合我的意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!