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: ( , 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()]}