Mike Robbins notes that the Compare-Object cmdlet in Powershell does not like to handle null values:
I thought I’d run into a bug with the Compare-Object cmdlet in PowerShell version 5.1 earlier today.
123 $DriveLetters = (Get-Volume).DriveLetter$DriveLettersCompare-Object -ReferenceObject $DriveLetters -DifferenceObject $DriveLettersCompare-Object : Cannot bind argument to parameter ‘ReferenceObject’ because it is null.
At line:1 char:33
+ Compare-Object -ReferenceObject $DriveLetters -DifferenceObject $Driv …
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Compare-Object], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.CompareObjectCommand
Read on for the description of the problem as well as the solution.