Unable to create a array from inside a if statement and export to csv

Try it without the quote marks around $null.

What I think is happening is the “$null” actually represents an empty string and an empty string is not the same as a null object.

$string = "$null"
Write-Output ($string -eq $null)