Hi,
Is there an easy way to get the SCSI-ID of a VMs Virtual Disks displayed in a Get-VM | Get-Harddisk output?
So far I could not find a way to retrieve the SCSI-IDs for the Virtual Disks in the same output as "Get-HardDisk".
It is simply not available, but it my opinion it should be there out of the box.
I managed to get the SCSI-IDs of the Virtual Disks by importing this function and then run the command Get-VM <MyVM> | Get-VMDisk,
but I don't like the output really and I would rather like to have an Object "SCSI-ID" in the "Get-Harddisk" cmdlet output.
One easy way is with a calculated property.
Get-VM | Get-HardDisk |
Select @{N='VM';E={$_.Parent.Name}},Name,@{N='SCSIid';E={$_.ExtensionData.UnitNumber}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luke,
thanks for your quick reply.
That comes close to what I was looking for, but it is still missing the Controller-ID.
As an example, here the output for one of our Oracle RAC-Node VMs:
PS P:\> Get-VM OSL2420 | Get-HardDisk | Select @{N='VM';E={$_.Parent.Name}},Name,@{N='SCSIid';E={$_.ExtensionData.UnitNumber}}
VM Name SCSIid
-- ---- ------
OSL2420 Hard disk 1 0
OSL2420 Hard disk 2 1
OSL2420 Hard disk 14 2
OSL2420 Hard disk 18 3
OSL2420 Hard disk 19 4
OSL2420 Hard disk 20 5
OSL2420 Hard disk 21 6
OSL2420 Hard disk 15 0
OSL2420 Hard disk 16 1
OSL2420 Hard disk 17 2
OSL2420 Hard disk 3 3
OSL2420 Hard disk 4 4
OSL2420 Hard disk 5 5
OSL2420 Hard disk 22 6
OSL2420 Hard disk 23 8
OSL2420 Hard disk 24 9
OSL2420 Hard disk 25 10
OSL2420 Hard disk 6 0
OSL2420 Hard disk 7 1
OSL2420 Hard disk 8 2
OSL2420 Hard disk 9 3
OSL2420 Hard disk 10 4
OSL2420 Hard disk 11 5
OSL2420 Hard disk 12 0
OSL2420 Hard disk 13 1
The vital piece of information I am missing in the output is the complete SCSI-ID that shows the controller ID followed by the Disk-ID in the same form as it is shown in the VM-Settings Dialog in the vSphere-Client.
The Disk-ID on its own is useless if you use more than one SCSI-Controller.
Is there any chance to get that full SCSI-ID displayed?
Ok, try like this
Get-VM | Get-HardDisk -PipelineVariable hd |
Select @{N='VM';E={$_.Parent.Name}},Name,@{N='SCSIid';E={
$ctrl = $hd.Parent.Extensiondata.Config.Hardware.Device | where{$_.Key -eq $hd.ExtensionData.ControllerKey}
"$($ctrl.BusNumber):$($_.ExtensionData.UnitNumber)"}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
that didnt help either.
The output leaves the SCSI-ID Column empty.:
VM Name SCSIid
-- ---- ------
OSL2420 Hard disk 1
OSL2420 Hard disk 2
OSL2420 Hard disk 14
OSL2420 Hard disk 18
OSL2420 Hard disk 19
OSL2420 Hard disk 20
OSL2420 Hard disk 21
OSL2420 Hard disk 15
OSL2420 Hard disk 16
OSL2420 Hard disk 17
OSL2420 Hard disk 3
OSL2420 Hard disk 4
OSL2420 Hard disk 5
OSL2420 Hard disk 22
OSL2420 Hard disk 23
OSL2420 Hard disk 24
OSL2420 Hard disk 25
OSL2420 Hard disk 6
OSL2420 Hard disk 7
OSL2420 Hard disk 8
OSL2420 Hard disk 9
OSL2420 Hard disk 10
OSL2420 Hard disk 11
OSL2420 Hard disk 12
OSL2420 Hard disk 13
Which PowerShell version are you using?
Do a $PSVersionTable.
The Pipeline variable I used was introduced in PS v4
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luke,
PS P:\> $PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
5 1 15063 726
PowerCLI Version
----------------
VMware PowerCLI 6.5.1 build 5377412
---------------
Component Versions
---------------
VMware Cis Core PowerCLI Component 6.5 build 6983166
VMware VimAutomation Core PowerCLI Component 6.5 build 6234650
Strange, that is exactly the same as I have.
And what happens when we leave out the pipelinevariable?
Get-VM | Get-HardDisk |
Select @{N='VM';E={$_.Parent.Name}},
Name,
@{N='SCSIid';E={
$hd = $_
$ctrl = $hd.Parent.Extensiondata.Config.Hardware.Device | where{$_.Key -eq $hd.ExtensionData.ControllerKey}
"$($ctrl.BusNumber):$($_.ExtensionData.UnitNumber)"
}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hey Luke,
this time the output looks much better. Thank you very much.
VM Name SCSIid
-- ---- ------
OSL2420 Hard disk 1 0:0
OSL2420 Hard disk 2 0:1
OSL2420 Hard disk 14 0:2
OSL2420 Hard disk 18 0:3
OSL2420 Hard disk 19 0:4
OSL2420 Hard disk 20 0:5
OSL2420 Hard disk 21 0:6
OSL2420 Hard disk 15 1:0
OSL2420 Hard disk 16 1:1
OSL2420 Hard disk 17 1:2
OSL2420 Hard disk 3 1:3
OSL2420 Hard disk 4 1:4
OSL2420 Hard disk 5 1:5
OSL2420 Hard disk 22 1:6
OSL2420 Hard disk 23 1:8
OSL2420 Hard disk 24 1:9
OSL2420 Hard disk 25 1:10
OSL2420 Hard disk 6 2:0
OSL2420 Hard disk 7 2:1
OSL2420 Hard disk 8 2:2
OSL2420 Hard disk 9 2:3
OSL2420 Hard disk 10 2:4
OSL2420 Hard disk 11 2:5
OSL2420 Hard disk 12 3:0
OSL2420 Hard disk 13 3:1
Try like this
Select @{N='VM';E={$_.Parent.Name}},
Name, Filename,
@{N='SCSIid';E={
$hd = $_
$ctrl = $hd.Parent.Extensiondata.Config.Hardware.Device | where{$_.Key -eq $hd.ExtensionData.ControllerKey}
"$($ctrl.BusNumber):$($_.ExtensionData.UnitNumber)"
}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luke,
this small script is very helpful to me as well but I wasn't able to extend it so far to get additional information.
Is it possible to get additional information like the VM UUID, VMDK UUID, SCSI Controller number and if possible the VMDK size visible in the WebClient beside the other output?
Thank you very much.
Try like this
Select @{N='VM';E={$_.Parent.Name}},
@{N='VM Uuid';E={$_.Parent.ExtensionData.Config.Uuid}},
Name,
Filename,
CapacityGB,
@{N='VMDK Uuid';E={$_.ExtensionData.Backing.Uuid}},
@{N='SCSIid';E={
$hd = $_
$ctrl = $hd.Parent.Extensiondata.Config.Hardware.Device | where{$_.Key -eq $hd.ExtensionData.ControllerKey}
"$($ctrl.BusNumber):$($_.ExtensionData.UnitNumber)"
}},
@{N='Controller#';E={(Get-ScsiController -HardDisk $_).UnitNumber}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luke,
thanks for the quick reply.
The output is exactly what I need.
I get the output
VM :
VM Uuid : 421d5e48-a184-a4e4-f107-ef89cead9b77
Name : Hard disk 2
Filename :
CapacityGB : 60
VMDK Uuid : 6000C293-dd64-b578-273c-3fdc6ef9ec98
SCSIid : 0:1
Controller# : 3
Is it possible to get the output side by side like VM, VM UUID, .... and to expport it to a CSV file?
That list format is driven by the size of your screen.
To export to a CSV, just pipe the result to Export-Csv
Select @{N = 'VM'; E = {$_.Parent.Name}},
@{N = 'VM Uuid'; E = {$_.Parent.ExtensionData.Config.Uuid}},
Name,
Filename,
CapacityGB,
@{N = 'VMDK Uuid'; E = {$_.ExtensionData.Backing.Uuid}},
@{N = 'SCSIid'; E = {
$hd = $_
$ctrl = $hd.Parent.Extensiondata.Config.Hardware.Device | where {$_.Key -eq $hd.ExtensionData.ControllerKey}
"$($ctrl.BusNumber):$($_.ExtensionData.UnitNumber)"
}
},
@{N = 'Controller#'; E = {(Get-ScsiController -HardDisk $_).UnitNumber}} |
Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I have checked the output and I'm not quite sure how to interpret the output for the SCSI controller. The Output is mostly 3 or 4 but not SCSI Controller 0 or SCSI Controller 1 as expected. Maybe the controller UnitNumber are different values. Can the output of SCSI Controller 0 like seen in the WebClient also be exported?
Isn't that 1st number (the BusNumber) in the SCSIid?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi luke,
Is there a way to get the VMdks for virtual machine
Something like the listed using Orchestrator (vRO)
VMName | VMdk | SCSI ID |
Isn't that what the script is showing?
Or do you mean something else?
Perhaps a sample of the output you mention would be helpful.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
After exporting the information to .csv file and when the csv file is opened with Excel the SCSI id value get change from 0:0 to 00:00 , 0:1 to 00:01 .. and so on. Can we restrict or format the column values while exporting?
VM | Name | Filename | SCSIid |
CH_Win2016 | Hard disk 1 | [iSCSI-2] CH_Win2016/CH_Win2016.vmdk | 00:00 |
CH_Win2016 | Hard disk 2 | [iSCSI-2] CH_Win2016/CH_Win2016_1.vmdk | 00:01 |
CH_Win2016 | Hard disk 3 | [iSCSI-2] CH_Win2016/CH_Win2016_2.vmdk | 00:02 |