PowerCLI

 View Only
  • 1.  Using PowerCLI to determine if my VM has an IDE or SCSI HardDisk

    Posted Oct 21, 2014 03:36 PM

    I am trying to find a method of using PowerCLI to determine if my VM's have IDE or SCSI hard disks (or both).  I need to start converting, but before I do so I need a solid list of what needs to be converted.

    Any thoughts?

    Thanks,

    Steven Wright



  • 2.  RE: Using PowerCLI to determine if my VM has an IDE or SCSI HardDisk

    Posted Oct 21, 2014 04:28 PM

    One way of doing that

    Get-VM | Get-HardDisk |

    Select @{N="VM";E={$_.Parent}}, Name,

        @{N="Type";E={Get-ScsiController -HardDisk $_ | Select -ExpandProperty Name}}



  • 3.  RE: Using PowerCLI to determine if my VM has an IDE or SCSI HardDisk

    Posted Oct 22, 2014 07:29 AM

    Thanks, this works pretty well - if it's a SCSI controller it indicates it, if not it produces { }.  Any idea how to add the specific cluster that the VM resides in as well?

    Thanks!!

    Steve Wright



  • 4.  RE: Using PowerCLI to determine if my VM has an IDE or SCSI HardDisk

    Posted Oct 22, 2014 09:26 AM

    Sure, try like this

    Get-VM | Get-HardDisk |

    Select @{N="VM";E={$_.Parent}}, Name,

        @{N="Cluster";E={Get-Cluster -VM $_.Parent | Select -ExpandProperty Name}},

        @{N="Type";E={Get-ScsiController -HardDisk $_ | Select -ExpandProperty Name}}



  • 5.  RE: Using PowerCLI to determine if my VM has an IDE or SCSI HardDisk

    Posted Oct 22, 2014 09:43 AM

    I had some problem with retreiving IDE targets from the get-scsicontrollerd cmd.

    Once I made a simple (not the best) script to retreive IDE or SCSI information from the Controllerkey.

    Like I said, it could be made probably a lot easier and faster.

    AFAIK

    IDE Controllerkey = 200

    SCSI Controllerkey = 1000

    So also could change the script to match 1000 else set it to unknown or something similar

    $Report = @()

    $VMs = Get-VM

        foreach ($VM in $VMs){

            $Disks = Get-HardDisk -VM $VM

                foreach ($disk in $Disks){

                    if ($disk.ExtensionData.ControllerKey -eq "200") {

                    $Row = "" | select Cluster,VM,Disk,Controller,Filename

                    $Row.Cluster = get-cluster -vm $VM

                    $Row.VM = $disk.Parent

                    $Row.Disk = $disk.Name

                    $Row.Controller = "IDE"

                    $Row.Filename = $disk.Filename

                    $Report += $Row

            }

            elseif ($disk.ExtensionData.ControllerKey -ne "200"){

                    $Row = "" | select Cluster,VM,Disk,Controller,Filename

                    $Row.Cluster = get-cluster -vm $VM

                    $Row.VM = $disk.Parent

                    $Row.Disk = $disk.Name

                    $Row.Controller = "SCSI"

                    $Row.Filename = $disk.Filename

                $Report += $Row

            }

        }

    }

    $report|ft -a



  • 6.  RE: Using PowerCLI to determine if my VM has an IDE or SCSI HardDisk

    Posted May 20, 2015 05:38 PM

    SO putting together everyone's ideas into a one-liner:

    Get-VMHost -Name <hostname> -Server <vCenterName> | Get-VM | Where-Object{$_.PowerState -eq "PoweredOn"} | Get-HardDisk | %{IF($_.ExtensionData.ControllerKey -eq 200){$_ | Select @{N="VM";E={$_.Parent.Name}},@{N="vControllerType";E={"IDE"}},Name,@{N="Path";E={$_.Filename}},@{N="StorageFormat";E={$_.StorageFormat}}} elseif ($disk.ExtensionData.ControllerKey -ne 200) {$_ | Select @{N="VM";E={$_.Parent.Name}},@{N="vControllerType";E={"SCSI"}},Name,@{N="Path";E={$_.Filename}},@{N="StorageFormat";E={$_.StorageFormat}}}}

    Outputs:

    VM              : VM1

    vControllerType : SCSI

    Name            : Hard disk 1

    Path            : [DataStoreName] VM1/VM1.vmdk

    StorageFormat   : Thin

    VM              :VM1

    vControllerType : SCSI

    Name            : Hard disk 2

    Path            : [DataStoreName] VM1/VM1_1.vmdk

    StorageFormat   : Thin

    VM              : VM2

    vControllerType : IDE

    Name            : Hard disk 1

    Path            : [DataStoreName] VM2/VM2.vmdk

    StorageFormat   : Thick