函数未返回预期对象 [英] Function not returning expected object
本文介绍了函数未返回预期对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对这个 PowerShell 函数有一个奇怪的情况.假设返回 ArrayList 对象,但在循环仅向 ArrayList 添加 1 个项目的情况下,该函数返回 SPList 项目而不是预期的 ArrayList 对象.我很困惑为什么 PowerShell 会这样.
I have a strange situation with this PowerShell function. It is suppose to return the ArrayList object but in the case when the loop only adds 1 item to the ArrayList the function returns the SPList item instead of the Expected ArrayList object. I am stumped on why PowerShell is behaving this way.
function Get-ContentOrganizerRules
(
[System.String]$siteUrl = "http://some.sharepoint.url"
)
{
Write-Host -ForegroundColor Gray "Searching for Content Organizer Rules: " $siteUrl
# ArrayList to hold any found DataConn Libs
[System.Collections.ArrayList]$CORules = New-Object System.Collections.ArrayList($null)
$lists = Get-SPWeb $siteUrl |
Select -ExpandProperty Lists |
Where { $_.GetType().Name -eq "SPList" -and $_.hidden }
foreach($list in $lists)
{
#Write-Host $list ;
foreach($contenType in $list.ContentTypes){
if($contenType -ne $null){
if($contenType.Id.ToString() -eq "0x0100DC2417D125A4489CA59DCC70E3F152B2000C65439F6CABB14AB9C55083A32BCE9C" -and $contenType.Name -eq "Rule")
{
$CORules.Add($list)>$null;
Write-Host -BackgroundColor Green -ForegroundColor White "Content Organizer Rule found: " $list.Url>$null;
}
}
}
}
return $CORules;
}
这是调用代码:
$CORulesResults = Get-ContentOrganizerRules $web.URL;
if($CORulesResults.Count -gt 0){
$Results.AddRange($CORulesResults);
}
推荐答案
那里有一个隐式管道,管道倾向于展开";数组、集合和数组列表一级.
There's a implicit pipeline there, and pipelines tend to "unroll" arrays, collections and arraylists one level.
试试这个:
return ,$CORules
这篇关于函数未返回预期对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文