接收工作:未获得结果

时间:2014-11-21 20:22:06

标签: powershell

我正在尝试从作业中返回组成员列表,但没有从Receive-Job获得任何结果。我想获取包含数组的变量或传递给新数组。

以下示例代码。如何让Receive-Job返回$objGroupMembers中的数据?

Start-Job -Name 'GroupName' -ScriptBlock {
    Get-PSSnapin -Registered | Add-PSSnapin;

    $aryProperties = @(
        "SamAccountName"
        "employeeid"
        "firstname"
        "lastname"
        "email"
        "title"
        "department"
    )

    $objGroupMembers = Get-QADGroupMember -Identity "GroupName" -Indirect -SizeLimit 0 -DontUseDefaultIncludedProperties -IncludedProperties $aryProperties | Select-Object $aryProperties 
}

1 个答案:

答案 0 :(得分:1)

你的工作没有归还任何东西。基本上一项工作就像在后台运行一个新的控制台。可以使用Receive-Job检索对该控制台所做的任何输出。但是,在您的情况下,您已将结果分配给您的变量并将其分配给您。以下内容应该有所帮助:

Start-Job -Name 'GroupName' -ScriptBlock {
    Get-PSSnapin -Registered | Add-PSSnapin;

    $aryProperties = @(
    "SamAccountName"
    "employeeid"
    "firstname"
    "lastname"
    "email"
    "title"
    "department"
    )


    $objGroupMembers = Get-QADGroupMember -Identity "GroupName" -Indirect -SizeLimit 0 -DontUseDefaultIncludedProperties -IncludedProperties $aryProperties | Select-Object $aryProperties 

    $objGroupMembers
}