VMware Cloud Community
jamesCHM
Contributor
Contributor
Jump to solution

Virtual Disk script failing for just 1 of my vms

Hello all, 

I hope someone can find the time to assist me. I have a script that we run through jenkins (i didnt create it) where we target a VM or number of VMs and it will collect and compile virtual disk read/write rates and compile into a csv, up until this one VM things have been working flawlessly. I am pretty new to powershell and i think my co worker has helped me identify the issue but im not sure how to fix it. The vm im working with is a large DB server with over 30 vmdks. 

The error message i recieve reads as follows "

powershell.exe : % : Exception calling "Add" with "2" argument(s): "Item has already been added. Key in dictionary: '0'  Key being 
At C:\Users\jenkins_au\jenkins\workspace\are_VMDK_Throughput_Limit_hourly@2@tmp\durable-747b5ce3\powershellWrapper.ps1:3 char:1
+ & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Comm ...

my co worker pointed me to the following lines in the script

$diskTab = @{}
$vm | Get-HardDisk | %{
    $diskTab.Add($_.ExtensionData.UnitNumber,$_.Name)
}

 

is there any guidance anyon can provide as to how i can check the vm to see why it is failing here?

 

James

Labels (3)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The problem is that the UnitNumber is unique on 1 controller.
If you have disks on multiple controllers, there are UnitNumbers that will be the same.
In a Hash table you can only use unique keys.

This shows the Harddisk name and the UnitNumber for a specific VM.
And will show identical UnitNumber values for more than 1 HardDisk

$vm = Get-VM -Name xyz
$vm.ExtensionData.Config.Hardware.Device | where {$_ -is [VMware.Vim.VirtualDisk]} | Select UnitNumber,@{N='Name';E={$_.DeviceInfo.Label}}



The solution could be to use the unique Key property of each HardDisk.

But in the rest of the code, there might be references to the hash table key that might have to be changed as well.
I can't tell without seeing the rest of the code


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

1 Reply
LucD
Leadership
Leadership
Jump to solution

The problem is that the UnitNumber is unique on 1 controller.
If you have disks on multiple controllers, there are UnitNumbers that will be the same.
In a Hash table you can only use unique keys.

This shows the Harddisk name and the UnitNumber for a specific VM.
And will show identical UnitNumber values for more than 1 HardDisk

$vm = Get-VM -Name xyz
$vm.ExtensionData.Config.Hardware.Device | where {$_ -is [VMware.Vim.VirtualDisk]} | Select UnitNumber,@{N='Name';E={$_.DeviceInfo.Label}}



The solution could be to use the unique Key property of each HardDisk.

But in the rest of the code, there might be references to the hash table key that might have to be changed as well.
I can't tell without seeing the rest of the code


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference