2

只是想知道你是否可以帮助我。我收到以下错误:

Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null.
At C:\PSScripts\CompassADStaff.ps1:33 char:20
+ $Staff | Export-Csv <<<<  CompassADStaff.csv -NoTypeInformation
+ CategoryInfo          : InvalidData: (:) [Export-Csv], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ExportCsvCommand

我的代码似乎没问题,但我似乎无法检测到 export-csv 生成上述错误的原因:

Import-Module ActiveDirectory

#-------- Object variables ----------------------------------------------

#OU's to search
$searchbase = "ou=staff1,ou=users,dc=home,dc=local","ou=staff2,ou=users,dc=home,dc=local"

$Staff = @()

#------------------------------------------------------------------------


foreach ($ou in $searchbase) {
$Staff += get-aduser -LDAPFilter "(&(objectCategory=person)(objectClass=user)(mail=*)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))" -SearchBase $ou -properties * | select-object employeeID,givenName,sn,sAMAccountName,mail
}
$Staff | Export-Csv CompassADStaff.csv -NoTypeInformation  

任何帮助或指示都会很棒:)

谢谢

4

2 回答 2

2

这始终为我解决了同样的问题:

$Staff | Where {$_} | Export-Csv CompassADStaff.csv -NoTypeInformation 
于 2017-03-31T07:43:06.553 回答
0

可以肯定的是,您可以像这样检查 $staff 中是否存在数据:

If ($Staff) {$Staff | Export-Csv CompassADStaff.csv -NoTypeInformation }
于 2013-10-04T14:15:06.243 回答