【发布时间】:2016-04-18 04:29:04
【问题描述】:
从 SharePoint 提取列表后,我需要根据其 BRTeam 值验证每个项目。这是脚本:
cls
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
Add-PSSnapin Microsoft.SharePoint.PowerShell;
}
$sourceWebUrl = "http://theoracle/WorkingHere/"
$sourceListName = "Policies & Procedures"
$spSourceWeb = Get-SPWeb $sourceWebUrl
$spSourceList = $spSourceWeb.Lists[$sourceListName]
$spSourceItems = $spSourceList.Items
$spSourceItems | ForEach-Object {
Write-Host $_['Name']
Write-Host $_['BRTeam']
}
代码在获取数据和将所需项目写入主机方面运行良好。
但是,如果我添加以下 If 语句来验证项目,我会看到一个错误:
if ($_['BRTeam'].Contains('HR')) {
Write-Host $_['Name']
Write-Host $_['BRTeam']
}
在分配$x = $_['BRTeam'] 后,我也尝试用$x -contains 'HR' 替换布尔检查,但这不会返回任何输出(也没有错误)。以下错误:
Method invocation failed because [Microsoft.SharePoint.Taxonomy.TaxonomyFieldValue] doesn't contain a method named 'Contains'.
At line:21 char:9
+ if ($_['BRTeam'].Contains('HR')) {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
谁能告诉我这里缺少什么?
【问题讨论】:
标签: arrays powershell sharepoint