Export-CSV inconsistent handling null objects

When I assign the variable $Users to the results of a Get-ADUser command, and it comes back with zero hits, I get a null variable that doesn’t error out in the code to export the results to csv, it just makes a blank csv file:
PS C:\Windows\system32> $Users = Get-ADUser -Filter {Name -notLike ‘Admin’ -and LastLogonDate -lt $InactiveDate -and Enabled -eq $true } -SearchBase $OU -Properties LastLogonDate, whenChanged | Select-Object @{ Name=“Username”; Expression={$_.SamAccountName} }, Name, LastLogonDate, whenChanged, DistinguishedName

PS C:\Windows\system32> ($users -eq $null)
True

PS C:\Windows\system32> $Users | Export-Csv C:\ADExports\InactiveCountyUsers.csv -NoTypeInformation

But when I do a op-add to add more users to the list with a different criteria, the returning results DO add to the variable when found, but when it finds nothing and the $Users variable stays null, it then errors when trying to export to csv?
PS C:\Windows\system32> $Users += Get-ADUser -Filter {Name -notLike ‘Admin’ -and LastLogonDate -notlike “*” -and whenChanged -lt $InactiveDate -and Enabled -eq $true} -SearchBase $OU -Properties LastLogonDate, whenChanged | Select-Object @{ Name=“Username”; Expression={$_.SamAccountName} }, Name, LastLogonDate, whenChanged, DistinguishedName

PS C:\Windows\system32> ($users -eq $null)
True

PS C:\Windows\system32> $Users | Export-Csv C:\ADExports\InactiveUsers.csv -NoTypeInformation
Export-Csv : Cannot bind argument to parameter ‘InputObject’ because it is null.
At line:1 char:10

  • $Users | Export-Csv C:\ADExports\InactiveUsers.csv -NoTypeInformation
  •      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidData: (:slight_smile: [Export-Csv], ParameterBindingValidationException
    • FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ExportCsvCommand

What gives?

David,
Welcome to the forum. :wave:t4:

Before we proceed - could you please go back, edit your question and fix the formatting of the code? You should format code, sample data or error mesasges as code here in the forum. So we are easily able to copy your code or sample data and reproduce your situation.
Thanks in advance.