gpt4 book ai didi

powershell - Powershell导出CSV错误

转载 作者:行者123 更新时间:2023-12-02 23:46:53 26 4
gpt4 key购买 nike

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

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

任何帮助或指针将是巨大的:)

谢谢

最佳答案

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

$Staff | Where {$_} | Export-Csv CompassADStaff.csv -NoTypeInformation 

关于powershell - Powershell导出CSV错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19180217/

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