VMware Cloud Community
marklemon
Enthusiast
Enthusiast
Jump to solution

listing SCSI Address or Virtual Disk Device with VM's Hard Disk number, Scsi Canonical Name and device

Hi, points for someone who can get the info from these two scripts to report in one command:

$vm="VMname"

$vmview = Get-View -ViewType VirtualMachine -Filter @{"Name" = $vm}

foreach ($VirtualSCSIController in ($vmview.Config.Hardware.Device | where {$_.DeviceInfo.Label -match "SCSI Controller"})) {

foreach ($VirtualDiskDevice in ($vmview.Config.Hardware.Device | where {$_.ControllerKey -eq $VirtualSCSIController.Key})) {

Write-Host SCSI" ("$($VirtualSCSIController.BusNumber):$($VirtualDiskDevice.UnitNumber)")" $VirtualDiskDevice.DeviceInfo.Label

}

}

This gives

SCSI (1:8) Hard disk 23

SCSI (1:9) Hard disk 24

SCSI (1:10) Hard disk 25

SCSI (1:12) Hard disk 26

SCSI (1:11) Hard disk 27

SCSI (1:13) Hard disk 28

SCSI (1:14) Hard disk 29

SCSI (1:15) Hard disk 30

which I found here:  http://www.virten.net/2015/08/match-linux-scsi-devices-sdx-to-virtual-disks-in-vmware/

and from VMware:

https://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=20018...

get-VM VMName | Get-HardDisk -DiskType "RawPhysical

","RawVirtual" | Select Parent,Name,DiskType,ScsiCanonicalName,DeviceName | fl >

List-VMName-RDMs.txt

which gives:

Parent            : VMName

Name              : Hard disk 29

DiskType          : RawPhysical

ScsiCanonicalName : naa.514f0c5411400124

DeviceName        : vml.02001f0000514f0c5411400124587472656d41

Parent            : VMName

Name              : Hard disk 30

DiskType          : RawPhysical

ScsiCanonicalName : naa.514f0c5411400125

DeviceName        : vml.0200200000514f0c5411400125587472656d41

Parent            : VMName

Name              : Hard disk 31

DiskType          : RawPhysical

ScsiCanonicalName : naa.514f0c5411400126

DeviceName        : vml.0200210000514f0c5411400126587472656d41

again, points for help in giving the script that will give both the info from this last script with the SCSI ID and hard disk count together.

cheers

KC

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You're probably on an older PowerShell version.

Check with $PSVersionTable


Try like this

$vm="vmname"

$vmview = Get-View -ViewType VirtualMachine -Filter @{"Name" = "^$($vm)$"}

foreach ($VirtualSCSIController in ($vmview.Config.Hardware.Device | where {$_.DeviceInfo.Label -match "SCSI Controller"})) {

    foreach ($VirtualDiskDevice in ($vmview.Config.Hardware.Device | where {$_.ControllerKey -eq $VirtualSCSIController.Key -and $_.Backing.GetType().Name -match "Raw"})) {

        New-Object PSObject -Property @{

            VM = $vmView.Name

            SCSI = "$($VirtualSCSIController.BusNumber):$($VirtualDiskDevice.UnitNumber)"

            HD = $VirtualDiskDevice.DeviceInfo.Label

            DiskType = $VirtualDiskDevice.Backing.CompatibilityMode

            ScsiCanonicalName = (Get-View -Id $vmView.Runtime.Host -Property Config.StorageDevice.ScsiLun).Config.StorageDevice.ScsiLun | where{$_.Uuid -eq $VirtualDiskDevice.Backing.LunUuid} | select -ExpandProperty CanonicalName

            DeviceName = $VirtualDiskDevice.Backing.DeviceName

        }

    }

}


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

View solution in original post

Reply
0 Kudos
14 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this

$vm="vmname"

$vmview = Get-View -ViewType VirtualMachine -Filter @{"Name" = "^$($vm)$"}

foreach ($VirtualSCSIController in ($vmview.Config.Hardware.Device | where {$_.DeviceInfo.Label -match "SCSI Controller"})) {

    foreach ($VirtualDiskDevice in ($vmview.Config.Hardware.Device | where {$_.ControllerKey -eq $VirtualSCSIController.Key -and $_.Backing.GetType().Name -match "Raw"})) {

        $obj = [ordered]@{

            VM = $vmView.Name

            SCSI = "$($VirtualSCSIController.BusNumber):$($VirtualDiskDevice.UnitNumber)"

            HD = $VirtualDiskDevice.DeviceInfo.Label

            DiskType = $VirtualDiskDevice.Backing.CompatibilityMode

            ScsiCanonicalName = (Get-View -Id $vmView.Runtime.Host -Property Config.StorageDevice.ScsiLun).Config.StorageDevice.ScsiLun | where{$_.Uuid -eq $VirtualDiskDevice.Backing.LunUuid} | select -ExpandProperty CanonicalName

            DeviceName = $VirtualDiskDevice.Backing.DeviceName

        }

        New-Object PSObject -Property $obj

    }

}


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

marklemon
Enthusiast
Enthusiast
Jump to solution

Thanks Luc.  Problem with the type of ordered?

Unable to find type [ordered]: make sure that the assembly containing this type

is loaded.

At line:3 char:25

+         $obj = [ordered] <<<< @{

    + CategoryInfo          : InvalidOperation: (ordered:String) [], RuntimeEx

   ception

    + FullyQualifiedErrorId : TypeNotFound

New-Object : Cannot validate argument on parameter 'Property'. The argument is

null or empty. Supply an argument that is not null or empty and then try the co

mmand again.

At line:11 char:38

+         New-Object PSObject -Property <<<<  $obj

    + CategoryInfo          : InvalidData: (:) [New-Object], ParameterBindingV

   alidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power

   Shell.Commands.NewObjectCommand

cheers

KC

PowerCLI F:\scripts\PowerCLI> Get-PowerCLIVersion

PowerCLI Version

----------------

   VMware vSphere PowerCLI 5.5 Release 1 build 1295336

---------------

Snapin Versions

---------------

   VMWare AutoDeploy PowerCLI Component 5.5 build 1262826

   VMWare ImageBuilder PowerCLI Component 5.5 build 1262826

   VMware License PowerCLI Component 5.5 build 1265954

   VMware VDS PowerCLI Component 5.5 build 1295334

   VMware vSphere PowerCLI Component 5.5 build 1295334

Reply
0 Kudos
marklemon
Enthusiast
Enthusiast
Jump to solution

seems googling a little further has given me what I'm looking for here:

http://notesofascripter.com/2015/10/26/powercli-to-get-information-about-rdm-connected-to-vm/

cheers,

KC

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You're probably on an older PowerShell version.

Check with $PSVersionTable


Try like this

$vm="vmname"

$vmview = Get-View -ViewType VirtualMachine -Filter @{"Name" = "^$($vm)$"}

foreach ($VirtualSCSIController in ($vmview.Config.Hardware.Device | where {$_.DeviceInfo.Label -match "SCSI Controller"})) {

    foreach ($VirtualDiskDevice in ($vmview.Config.Hardware.Device | where {$_.ControllerKey -eq $VirtualSCSIController.Key -and $_.Backing.GetType().Name -match "Raw"})) {

        New-Object PSObject -Property @{

            VM = $vmView.Name

            SCSI = "$($VirtualSCSIController.BusNumber):$($VirtualDiskDevice.UnitNumber)"

            HD = $VirtualDiskDevice.DeviceInfo.Label

            DiskType = $VirtualDiskDevice.Backing.CompatibilityMode

            ScsiCanonicalName = (Get-View -Id $vmView.Runtime.Host -Property Config.StorageDevice.ScsiLun).Config.StorageDevice.ScsiLun | where{$_.Uuid -eq $VirtualDiskDevice.Backing.LunUuid} | select -ExpandProperty CanonicalName

            DeviceName = $VirtualDiskDevice.Backing.DeviceName

        }

    }

}


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

Reply
0 Kudos
marklemon
Enthusiast
Enthusiast
Jump to solution

Thanks, Luc.  I posted the version of my PowerCLI (5.5) in my first reply to this thread.  The last version you posted did the trick.

cheers

KC

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

It's not the PowerCLI version, but the PowerShell version that doesn't recognise the [ordered] cast.


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

Reply
0 Kudos
bikashyadav
Contributor
Contributor
Jump to solution

Hi LucD,

This is listing all the RDM disk info. What about the flat disks?

I added $_.Backing.GetType().Name -notlike "Raw" in below script but its not working. What needs to be modified here to list all disks including flat along with rdms.

param([string]$VMName)

$vmview = Get-View -ViewType VirtualMachine -Filter @{"Name" = "^$($VMName)$"}

&{foreach ($VirtualSCSIController in ($vmview.Config.Hardware.Device | where {$_.DeviceInfo.Label -match "SCSI Controller"})) {

    foreach ($VirtualDiskDevice in ($vmview.Config.Hardware.Device | where {$_.ControllerKey -eq $VirtualSCSIController.Key -and $_.Backing.GetType().Name -match "Raw" -and $_.Backing.GetType().Name -notlike "Raw"  })) {

        $obj = [ordered] @{

            VM = $vmView.Name

            ControllerTYpe = $VirtualSCSIController.DeviceInfo.Summary

            DiskType = $VirtualDiskDevice.Backing.CompatibilityMode

            DiskName = $VirtualDiskDevice.DeviceInfo.Label

            SCSI_ID = "$($VirtualSCSIController.BusNumber):$($VirtualDiskDevice.UnitNumber)"

            DeviceName = $VirtualDiskDevice.Backing.DeviceName

            DiskFile = $VirtualDiskDevice.Backing.FileName

            ScsiCanonicalName = (Get-View -Id $vmView.Runtime.Host -Property Config.StorageDevice.ScsiLun).Config.StorageDevice.ScsiLun | where{$_.Uuid -eq $VirtualDiskDevice.Backing.LunUuid} | select -ExpandProperty CanonicalName

            DiskSizeGB = $VirtualDiskDevice.CapacityInKB * 1KB / 1GB

           

        }

    }

}} | ft -AutoSize

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

If you want all disks (RDM and non-RDM), you could do

foreach ($VirtualDiskDevice in ($vmview.Config.Hardware.Device |

    where {$_.ControllerKey -eq $VirtualSCSIController.Key}))


If you only want non-RDM, you could do

foreach ($VirtualDiskDevice in ($vmview.Config.Hardware.Device |

    where {$_.ControllerKey -eq $VirtualSCSIController.Key -and $_.Backing.GetType().Name -notmatch "Raw"}))


But be aware that several properties in the result will not make sense for non-RDM harddisks.


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

Reply
0 Kudos
bikashyadav
Contributor
Contributor
Jump to solution

I ran the command and got all disks listed but the disktype for the non-rdms are blank. Its doesnt say flat disk type.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, the property the script uses does not exist for non-RDM disks.
You will have to adapt the script accordingly if you want the value 'flat' in there.


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

Reply
0 Kudos
bikashyadav
Contributor
Contributor
Jump to solution

I used this script to get the same result. Which show disktype as flat & also rdms disk as well. but the out for each disk is show multiple time. Say if i have 5 disks i will get 5 same output for each disk contributing to 25 disk output. See screenshot below. Am i missing something here ?

param([string]$VMName)

$DiskInfo= @()

foreach ($VM in Get-VM $VMName){

foreach ($VirtualSCSIController in ($VM.ExtensionData.Config.Hardware.Device | Where-Object { $_.DeviceInfo.Label -match "SCSI Controller" -or $_.DeviceInfo.Label -match "SATA Controller" })) {

foreach ($VirtualDiskDevice in ($VM.ExtensionData.Config.Hardware.Device | where {$_.ControllerKey -eq $VirtualSCSIController.Key})) {

foreach ($DiskType in ($VM | Get-HardDisk)){

$VirtualDisk = "" | Select VMname,Controller,ControllerType,DiskType,DiskName,SCSI_ID,DeviceName,DiskFile,DiskSizeGB

$VirtualDisk.VMname = $VM.Name

$VirtualDisk.Controller = $VirtualSCSIController.DeviceInfo.Label

$VirtualDisk.ControllerType = $VirtualSCSIController.DeviceInfo.Summary

$VirtualDisk.DiskType = $DiskType.DiskType

$VirtualDisk.DiskName = $VirtualDiskDevice.DeviceInfo.Label

$VirtualDisk.SCSI_ID = "$($VirtualSCSIController.BusNumber):$($VirtualDiskDevice.UnitNumber)"

$VirtualDisk.DeviceName = $VirtualDiskDevice.Backing.DeviceName

$VirtualDisk.DiskFile = $VirtualDiskDevice.Backing.FileName

$VirtualDisk.DiskSizeGB = $VirtualDiskDevice.CapacityInKB * 1KB / 1GB

$DiskInfo += $VirtualDisk

}}}}

$DiskInfo | ft -Autosize

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Although you have 2 loops going through all the SCSI controllers and all devices connected to each controller, your most inner loop goes over all harddisk connected to the VM


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

Reply
0 Kudos
bikashyadav
Contributor
Contributor
Jump to solution

So any lead on how do i modify it to fix it ?

I tried but not able to get to the solution.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I suggest you open a new thread because this is now going far away from the original question in this thread on which you piggy-backed.


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

Reply
0 Kudos