Function powershell函数将嵌套对象(每个嵌套对象有一行)视为一个对象

Function powershell函数将嵌套对象(每个嵌套对象有一行)视为一个对象,function,powershell,nested,powershell-3.0,Function,Powershell,Nested,Powershell 3.0,我现在有类似的东西(Powershell v3): 功能(另存为文件): 还有剧本: C:\tools\Scripts\functions\Send-MailWithFormattedTables.ps1 $Parameters = @{ objects = $object1, $object2 } Send-MailWithFormattedTables @Parameters 有时是一个对象(在这种情况下这很重要)或两个以上的对象。还有很多其他参数,但现在已经无关紧要了。 这一切

我现在有类似的东西(Powershell v3):

功能(另存为文件):

还有剧本:

C:\tools\Scripts\functions\Send-MailWithFormattedTables.ps1
$Parameters = @{
    objects = $object1, $object2 
}
Send-MailWithFormattedTables @Parameters
有时是一个对象(在这种情况下这很重要)或两个以上的对象。还有很多其他参数,但现在已经无关紧要了。 这一切都很好,但只适用于每个对象有超过1行的情况。 发生这种情况时,函数将两个对象视为一个对象(将两个单独的行连接到一个对象),并枚举每一行而不是每个对象。 我试过:

没有正面效果。 当我在不使用函数的情况下执行代码时(即使两个对象只有一行),一切都很好:

如何防止这种行为

顺便说一句,该函数使用任意数量的对象调用,并将它们作为html单独的表发送到电子邮件中。每个表都有独特的标题。 如下所示(不使用函数-两个对象各有一行):


谢谢你的帮助

您是否尝试过将$object1和$object2显式声明为数组?像
$object1=@(value)
听起来您需要使用Begin/Process/End完全格式化您的函数,以便在Begin中设置邮件,在流程中添加对象作为内容,最后发送邮件。另外,您可能希望将其定义为[Array]$Objects,因为您希望能够解析对象数组。我得试试。不管对我有没有帮助,我都会写信的。
C:\tools\Scripts\functions\Send-MailWithFormattedTables.ps1
$Parameters = @{
    objects = $object1, $object2 
}
Send-MailWithFormattedTables @Parameters
$Parameters = @{
    objects = [object]$object1, [object]$object2
    #..and other parameters
}
$Objects = $object1, $object2
Foreach ($object in $Tables){
    #each object is enumerated
}