Get-wmiObject Windows disk info powershell error

I am trying to run a powershell script to map Windows disk volumes to EC2 Volumes. My script is breaking on a Windows 2008 machine but works fine on a windows 2012 machine. This is the original script

On a Windows 2008 machine if I run the below snippet I get an error message. it works fine on a Windows 2012 machine. Any ideas?

You must provide a value expression on the right-hand side of the ‘-’ operator.
At line:9 char:98

  •     $Disk = Get-WmiObject -Class Win32_LogicalDiskToPartition | Where-Object {$_.Antecedent - <<<< in $D2P.Depend
    

ent} | %{
+ CategoryInfo : ParserError: (:slight_smile: , ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ExpectedValueExpression


Powershell code:

Get-WmiObject -Class Win32_DiskDrive | % {
$Drive = $_
# Find the partitions for this drive
Get-WmiObject -Class Win32_DiskDriveToDiskPartition | Where-Object {$.Antecedent -eq $Drive.Path.Path} | %{
$D2P = $

# Get details about each partition
$Partition = Get-WmiObject -Class Win32_DiskPartition | Where-Object {$.Path.Path -eq $D2P.Dependent}
# Find the drive that this partition is linked to
$Disk = Get-WmiObject -Class Win32_LogicalDiskToPartition | Where-Object {$
.Antecedent -in $D2P.Dependent} | %{
$L2P = $_
#Get the drive letter for this partition, if there is one
Get-WmiObject -Class Win32_LogicalDisk | Where-Object {$.Path.Path -in $L2P.Dependent}
}
$BlockDeviceMapping = $BlockDeviceMappings | Where-Object {$
.DeviceName -eq $Map[$Drive.SCSITargetId.ToString()]}

It would be a little easier to read this if you took a moment to format the code, as indicated in the instructions above the text box. As-is, it’s all running together and I’m having trouble interpreting it.

However, it appears that you’re using the -in operator, which didn’t exist in older versions of PowerShell. You might try re-writing your comparison logic to use -contains, which goes back to v1.0.

Thanks for your valuable insight Don. You were right the -in operator was causing the issue. When I changed that to -contains it worked perfect.