Automation

 View Only
  • 1.  List properties of all VM

    Posted Sep 03, 2010 11:16 AM

    Hi all,

    We are migrating from ESX 3.0.2 to ESX 4 U2. We intend to migrate the VM lun per lun.

    At the begining, we take a look in the SQL database of VC. But I think the best way is to use the powercli. But I'm a newbee in Powershell too !

    VM are connected to 2 switches. So they have at leat 2 IP on different subnet. We use 2 vswitches. They have 2 or 3 vdisks

    I need to create a .csv file with the following infos :

    VM-name, Operating System, Cluster name, HostName, VM-IPs, Disks size of the VM, Datastore Name, Lun info

    Thanks for any help !

    Best regards

    ML



  • 2.  RE: List properties of all VM

    Posted Sep 03, 2010 03:00 PM

    Have you tried PowerGUI or Virizoncore's free EcoShell (based off PowerGUI). These tools wrap a gui around PowerCLI and make gather info previously only available through writing your script more accessible.

    When you say you want the following info - are you wanting that listed per host?

    VM-name, Operating System, Cluster name, HostName, VM-IPs, Disks size of the VM, Datastore Name, Lun info



  • 3.  RE: List properties of all VM

    Posted Sep 03, 2010 03:45 PM

    hi,

    Thanks, I will have a look to these tools

    I want this list for every VM in the VC. By host, or by datastore. With excel, I will sort according my needs

    Regards

    ML



  • 4.  RE: List properties of all VM

    Posted Sep 03, 2010 04:31 PM

    I took a stab at it. HOpefully someone can clean this up or make it work a little better. I'm not quite sure how to output this into cvs to make it look right.

    Here's what I have so far:

    $VMs = Get-VM

    foreach($vm in $VMs){

    $vm_name = $vm | Select Name,Host

    $vm_guest = $vm.guest | Select OSFullName,IPAddress

    $vm_hd = $vm.HardDisks | Select Name,CapacityKB,Filename}

    I couldn't figure out how to combine the Select-Object statements or drill down to the Guest.OSFullName property. This is a start though. Good luck.



  • 5.  RE: List properties of all VM

    Posted Sep 03, 2010 06:10 PM

    Hi ML,

    the next PowerCLI script creates a file VMs.csv with the requested properties of all your virtual machines:

    Get-VM | Select-Object -Property Name,
    @{N="Operating System";E={$_.Guest.OSFullName}},
    @{N="Cluster";E={(Get-Cluster -VM $_).Name}},
    VMhost,
    @{N="IPAddress";E={$($_.Guest.IPAddress)}},
    UsedSpaceGB,
    @{N="Datastore";E={(Get-Datastore -VM $_).Name}},
    @{N="Lun";E={(Get-Datastore -VM $_ | Get-ScsiLun).CanonicalName.Split(":")[2]}} | `
    Export-Csv -NoTypeInformation -Path VMs.csv
    

    Regards, Robert



  • 6.  RE: List properties of all VM

    Posted Sep 06, 2010 07:41 AM

    Hi

    Thank you for your help :smileygrin:

    But I get errors on some VM (I think, some are ok).

    I remind you that I query a VC 2.5

    The column UseGB contains -1 in every lines

    The column Lun, 0 in every lines.

    Best regards

    ML

    Select-Object : You cannot call a method on a null-valued expression.

    At C:\Users\mld\Desktop\liste-vm.ps1:4 char:23

    + Get-VM | Select-Object <<<< -Property Name, @{N="Operating System";E={$_.Guest.OSFullName}}, @{N="Cluster";E={(Get-C

    luster -VM $_).Name}}, VMhost, @{N="IPAddress";E={$($_.Guest.IPAddress)}}, UsedSpaceGB,@{N="Datastore";E={(Get-Datastor

    e -VM $_).Name}}, @{N="Lun";E={(Get-Datastore -VM $_ | Get-ScsiLun).CanonicalName.Split(":")[2]}} | Export-Csv -NoTypeI

    nformation -Path VMs.csv



  • 7.  RE: List properties of all VM

    Posted Sep 06, 2010 01:40 PM

    I have only vCenter v4.1 servers to test so I didn't notice the problems with v2.5. :smileysad: I changed the script a little. It now uses the Get-HardDisk cmdlet to retrieve the size of the hard disks. And the script returns the canonical name of lun. I hope it will work correct now.

    Get-VM | Select-Object -Property Name,
    @{N="Operating System";E={$_.Guest.OSFullName}},
    @{N="Cluster";E={(Get-Cluster -VM $_).Name}},
    VMhost,
    @{N="IPAddress";E={$($_.Guest.IPAddress)}},
    @{N="UsedSpaceGB";E={$UsedSpaceGB=0;$_|Get-HardDisk|ForEach-Object{$UsedSpaceGB+=$_.CapacityKB/1MB};$UsedSpaceGB}},
    @{N="Datastore";E={(Get-Datastore -VM $_).Name}},
    @{N="Lun";E={(Get-Datastore -VM $_ | Get-ScsiLun).CanonicalName}} | `
    Export-Csv -NoTypeInformation -Path VMs.csv
    



  • 8.  RE: List properties of all VM

    Posted Sep 06, 2010 04:38 PM

    Hi,

    It's better, but the lun colum now shows something like :vmhab0:1:0, but I would like the lun name, as can be seen in VC :

    Host>Configuration Tab.

    One can see the list of hbas in Storage adapters, Device colum.

    click on one hba

    Then , in details section, on the bottom, one can see the list of the luns connected to the hba. This is the information I would like to see (datastore => Lun name of this datastore).

    Thanks a lot !!

    best regards

    ML



  • 9.  RE: List properties of all VM

    Posted Sep 09, 2010 08:12 AM

    I am sorry, but I am not sure what you mean. The problem is that the storage adapters screen layout depends on the version of the ESX server and differs if you have a direct connection to the ESX server or a connection via the vCenter server. Maybe you can post a screenshot of your storage adapters screen and highlight the information you want?