# Get-wmiObject Windows disk info powershell error

**URL:** <https://forums.powershell.org/t/get-wmiobject-windows-disk-info-powershell-error/4812>\
**Category:** PowerShell Help\
**Created:** [September 3, 2015, 12:38am UTC](https://forums.powershell.org/t/get-wmiobject-windows-disk-info-powershell-error/4812 "2015-09-03T00:38:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ripul-handa](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@ripul-handa](https://forums.powershell.org/u/ripul-handa)\
**Post date:** [September 3, 2015, 12:38am UTC](https://forums.powershell.org/t/get-wmiobject-windows-disk-info-powershell-error/4812/1 "2015-09-03T00:38:59Z")

</div>

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

> **[Map disks to volumes on your Windows instance - Amazon Elastic Compute Cloud](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-windows-volumes.html)**
>
> Your Windows instance comes with an EBS volume that serves as the root volume. If your Windows instance uses AWS PV or Citrix PV drivers, you can optionally add up to 25 volumes, making a total of 26 volumes. For more information, see .

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 - &lt;&lt;&lt;&lt; in $D2P.Depend

```

ent} | %{  
+ CategoryInfo : ParserError: (🙂 , 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()]}

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [September 3, 2015, 12:49am UTC](https://forums.powershell.org/t/get-wmiobject-windows-disk-info-powershell-error/4812/2 "2015-09-03T00:49:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ripul-handa](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@ripul-handa](https://forums.powershell.org/u/ripul-handa)\
**Post date:** [September 3, 2015, 12:59am UTC](https://forums.powershell.org/t/get-wmiobject-windows-disk-info-powershell-error/4812/3 "2015-09-03T00:59:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:44pm UTC](https://forums.powershell.org/t/get-wmiobject-windows-disk-info-powershell-error/4812/4 "2024-05-16T20:44:49Z")

</div>

Closed on May 16, 2024, 8:44pm UTC


