gpt4 book ai didi

powershell - 函数未返回预期对象

转载 作者:行者123 更新时间:2023-12-04 06:40:44 25 4
gpt4 key购买 nike

我对这个 PowerShell 函数有一个奇怪的情况。假设返回 ArrayList 对象,但在循环仅向 ArrayList 添加 1 个项目的情况下,该函数返回 SPList 项目而不是预期的 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);
}

最佳答案

那里有一个隐式管道,管道倾向于将数组、集合和数组列表“展开”一层。
尝试这个:

return ,$CORules

关于powershell - 函数未返回预期对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16121969/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com