Kristoffer Ekenhammar
Kristoffer Ekenhammar

Reputation: 11

Fail to run Compare-Object in Windows 10

I´m trying to run Compare-Object for a mounted ISO. These 3 lines works perfect with v 4.0 in Windows 8.1.

$Driveletters = (Get-Volume).Driveletter
$SetupDriveLetter = (Mount-DiskImage -ImagePath "Mypath")
$ISODriveletter = (Compare-Object -ReferenceObject $DriveLetters -DifferenceObject (Get-Volume).DriveLetter).InputObject 

When I run the same lines in Windows 10, I´m presented with the following error. What am I doing wrong? Does anyone has any suggestions I would really appreciate it.

Compare-Object : Cannot bind argument to parameter 'ReferenceObject' because it is null. At line:1 char:55 + ... ODriveletter = (Compare-Object -ReferenceObject $DriveLetters -Differ ... + ~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Compare-Object], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.CompareObjectCommand

Upvotes: 1

Views: 521

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174690

As determined in the comments, your $DriveLetters array contains at least one $null-value item. You can filter away items with no value using Where-Object:

$DriveLetters = (Get-Volume).DriveLetter |Where-Object { $_ }

Upvotes: 1

Related Questions