powershell - 我是否正确编码此Powershell?因为它没有达到我的预期

标签 powershell sharepoint-2010

需要从名为“Region”的字段名称中找出文档集名称。我需要将文档集名称设置为任何区域(NW,SW,NE,SE等),并将文件从文档库的根目录移至其受尊重的文档集。我不介意对网站或Web网址和doc lib网址进行硬编码。我收到此错误:

','之后缺少表达式。在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();
            }
}

最佳答案

第二个参数应该是$true,而不仅仅是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.



更具描述性,解决方法在错误消息中!

关于powershell - 我是否正确编码此Powershell?因为它没有达到我的预期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7208375/

相关文章:

sql - 有效地替换大型CSV中列中的文本

powershell:如何使用 ls dirA,dirB -rec |组文件名,版本信息。产品版本 |英尺-自动...?

sharepoint - Safari 7.1中的ASPMenu在SharePoint 2010中无法正确呈现

sharepoint-2010 - "An unexpected System Error has occured. Additional details have been logged for yor Administrator."

sharepoint - 如何纠正此自动删除Sharepoint备份的PowerShell脚本

.net - 服务不可用 管理中心 SharePoint 2010

powershell - 使用Get-childitem获取最近3天内修改的文件列表

powershell - PowerShell-使用WebDAV下载文件

powershell - 检查项目是否存在,如果不存在,则显示错误

c# - 如何获取 SharePoint 2010 Web 应用程序范围的功能以仅在一个 Web 应用程序上激活