Export-Csv无法将参数绑定到参数“ InputObject”,因为它为null

时间:2018-09-18 05:32:44

标签: active-directory powershell-v3.0

我正在尝试通过Power Shell来获取AD组成员信息。但是我收到的消息是

  

Export-Csv:无法将参数绑定到参数'InputObject',因为它为空。

Import-Module ActiveDirectory

$Path = Get-Location

$GroupName = Read-Host "Type the Group Name to check the members in it`t "

foreach ($group in $GroupName) {
    $users = @{}

    Get-ADUser -Filter '*' -Property Name, DisplayName | ForEach-Object {
        $users[$_.DistinguishedName] = $_
    }

    $MemberCount = (Get-ADGroup $group -Properties Member | Select-Object -Expand Member).Count

    Write-Host "`t Total Number of Users/Groups added on this Group : $MemberCount" -BackgroundColor DarkCyan

    $Info = Get-ADGroup $group -Properties Member |
            Select-Object -Expand Member |
            ForEach-Object { $users[$_] }

    $Info | Export-Csv -NoTypeInformation -Append -Force $Path\new.csv

1 个答案:

答案 0 :(得分:0)

该错误表示$Info包含空/空值。他们出现的最可能原因是该网上论坛的成员不是Get-ADUser返回的。

您可以通过检查$users哈希表中密钥的存在来避免该问题:

$Info = Get-ADGroup $group -Properties Member |
        Select-Object -Expand Member |
        ForEach-Object { if ($users.ContainsKey($_) {$users[$_]} }

如果您想进一步调查缺失的专有名称,可以这样收集它们:

$missing = Get-ADGroup $group -Properties Member |
           Select-Object -Expand Member |
           ForEach-Object { if (-not $users.ContainsKey($_) {$_} }