我有這個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