2

Just wondered if you can help me please. I receive the following error:

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

My code seems OK but I can't seem to detect why export-csv generates the above error:

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  

Any help or pointers would be great :)

Thanks

3
  • Are you certain there is data in $Staff when you try to export it? Commented Oct 4, 2013 at 12:30
  • totally as I have stepped through and a csv is created with the required data. Its just that it errors. Thanks Commented Oct 4, 2013 at 13:09
  • That code works fine for me. From what I can see, the error would be generated when $Staff is empty before the export. As you say it is still exporting data, I don't know what could be causing it. Commented Oct 4, 2013 at 13:47

2 Answers 2

2

This consistently resolved the same problem for me:

$Staff | Where {$_} | Export-Csv CompassADStaff.csv -NoTypeInformation 
Sign up to request clarification or add additional context in comments.

Comments

0

Just to be sure, can you check for existence of data in $staff like this:

If ($Staff) {$Staff | Export-Csv CompassADStaff.csv -NoTypeInformation }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.