我有这个PowerShell函数的一个奇怪的情况。假设返回ArrayList对象,但是在循环仅向ArrayList添加1个项的情况下,函数返回SPList项而不是Expected ArrayList对象。我难以理解PowerShell为何如此行事。函数不返回预期的对象
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);
}
'是否会“展开”数组'你是什么意思?想要展开,不会展开,展开数组,还有其他什么? – Neolisk 2013-04-21 01:58:16
古英语。这意味着“他们将获得一切机会”。 – mjolinor 2013-04-21 04:48:52