1

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

Vikash Pandey
  • 5,407
  • 6
  • 41
  • 42
  • 1
    Do you have any volume without drive letter? – user4003407 Jan 15 '16 at 10:10
  • Unfortunately not, good tip though. Have tried this on several Windows 10 machines with the same result. – Kristoffer Ekenhammar Jan 15 '16 at 10:15
  • 2
    @KristofferEkenhammar Are you absolutely sure? Does `$DriveLetters.Count` match the number of drive letters listed when you issue `"$DriveLetters"` at the prompt? I'm having a hard time believing you don't have at least one driveletter-less system reserved partition – Mathias R. Jessen Jan 15 '16 at 11:59
  • Sorry guys, you´re absolutley right, I do have letter-less reserved partitions. Ok, so I really don´t understand why that would affect me. The thing I want to do is to get my driveletters, mount the ISO and then compare what changes has been made. Why does letter-less drives prohibits that? Just running '$Driveletters' with a return gives me C, but '$Driveletters.Count' returns 3. Is there another way to do this? – Kristoffer Ekenhammar Jan 15 '16 at 12:43
  • Thanks for the help, ended up using another way. Sorry for bugging you. $ISO = 'mypath' Mount-DiskImage -ImagePath $ISO -StorageType ISO $ISODriveLetter = (Get-DiskImage -ImagePath $ISO | Get-Volume).DriveLetter Write-Host ("ISO Drive should be " + $ISODriveLetter) seems to work now. – Kristoffer Ekenhammar Jan 15 '16 at 13:56
  • @MathiasR.Jessen how do you specify code in the comments section? – Anthony Stringer Jan 15 '16 at 15:01
  • Backticks surrounding your snip :-) – Mathias R. Jessen Jan 15 '16 at 15:22

1 Answers1

1

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 { $_ }
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206