Automation

 View Only
  • 1.  Using the GET-VM command

    Posted Apr 24, 2019 04:57 PM
    Hello everyone, I wanted to request your help.  I am using the GET-VM command in the following way:  Get-VM | Select-Object Name, NumCPU, MemoryMB, PowerState, Host  He gives me everything except the value of HOST.  Any ideas?  I'm using Esxi 5.5


  • 2.  RE: Using the GET-VM command

    Posted Apr 24, 2019 05:02 PM

    The property is named VMHost, not Host.

    Get-VM | Select-Object Name, NumCPU, MemoryMB, PowerState, VMHost



  • 3.  RE: Using the GET-VM command

    Posted Apr 24, 2019 11:07 PM

    Thank you... :smileyhappy:

    Get-VM | Sort | Get-View -Property @("Name", "Config.GuestFullName", "Guest.GuestFullName") | Select -Property Name, @{N="Configured OS";E={$_.Config.GuestFullName}},  @{N="Running OS";E={$_.Guest.GuestFullName}} | Format-Table -AutoSize

    This script allows me to know the name of the VM and its operating system, but I have not been able to link it with data like the ones I get with

    Get-VM | Select-Object VMHost, Name, NumCPU, MemoryMB, PowerState, @ {N = "IP VM"; E = {@ ($ _. Guest.IPAddress [0])}} | Format-Table -AutoSize

    Number of CPU

    RAM

    State of energy

    IP of the VM

    Any ideas?



  • 4.  RE: Using the GET-VM command

    Posted Apr 25, 2019 06:24 AM

    You could do something like this

    Get-View -ViewType VirtualMachine -Property 'Name','Config.Hardware','Guest','Runtime' |

    Sort-Object |

    Select -Property Name,

       @{N='NumCpu';E={$_.Config.Hardware.NumCPU}},

       @{N='MemGB';E={[math]::Round($_.Config.Hardware.MemoryMB/1KB,1)}},

       @{N='PowerState';E={$_.RunTime.PowerState}},

       @{N='IP';E={$_.Guest.IpAddress}},

       @{N="Configured OS";E={$_.Config.GuestFullName}},

       @{N="Running OS";E={$_.Guest.GuestFullName}} |

    Format-Table -AutoSize



  • 5.  RE: Using the GET-VM command

    Posted Apr 25, 2019 03:12 PM

    Thank You!!

    I made a small modification....

    Get-View -ViewType VirtualMachine -Property 'Name','Config.Hardware','Guest','Runtime' ,'Config.GuestFullName'|

    Sort-Object |Select -Property Name,@{N='NumCpu';E={$_.Config.Hardware.NumCPU}},@{N='MemoryMB';E={[math]::Round($_.Config.Hardware.MemoryMB/1KB,1)}},

    @{N='PowerState';E={$_.RunTime.PowerState}}, @{N='IP';E={$_.Guest.IpAddress}}, @{N="OS_Configurado";E={$_.Config.GuestFullName}},

    @{N="Running OS";E={$_.Guest.GuestFullName}} |Format-Table -AutoSize

    question, how could the VMHost or the Esxi to which the VM belongs in this query add to the result?

    Thank you



  • 6.  RE: Using the GET-VM command

    Posted Apr 25, 2019 03:33 PM

    That property contains a value that is derived from the GuestId (which is specified during the creation of the VM).
    It could be that the value, which is not required, was not provided.
    Check what is in GuestId.

    There are no real PowerShell/PowerCLI "learning" books for the vSphere objects.
    The ultimate guide is the VMware vSphere API Reference, but since it is a reference, it is not really something for learning.

    There is also the VMware vSphere Automation SDKs Programming Guide which is not too bad, but requires a certain level of vSphere and coding knowledge.

    And there is a dedicated chapter in the PowerCLI Reference on the SDK and how to use it from PowerCLI.



  • 7.  RE: Using the GET-VM command
    Best Answer

    Posted Apr 25, 2019 03:37 PM

    Try like this

    Get-View -ViewType VirtualMachine -Property 'Name','Config.Hardware','Guest','Runtime' ,'Config.GuestFullName'|

    Sort-Object |

    Select -Property Name,

       @{N='VMHost';E={(Get-View -Id $_.Runtime.Host -Property Name).Name}},

       @{N='NumCpu';E={$_.Config.Hardware.NumCPU}},

       @{N='MemoryMB';E={[math]::Round($_.Config.Hardware.MemoryMB/1KB,1)}},

       @{N='PowerState';E={$_.RunTime.PowerState}},

       @{N='IP';E={$_.Guest.IpAddress}},

       @{N="OS_Configurado";E={$_.Config.GuestFullName}},

       @{N="Running OS";E={$_.Guest.GuestFullName}} |

    Format-Table -AutoSize



  • 8.  RE: Using the GET-VM command

    Posted Apr 26, 2019 07:09 PM

    Thank you :smileyhappy:

    question, is it possible to know how many resources are consuming in CPU, RAM and disk IO in this same query for each VM?

    Thank



  • 9.  RE: Using the GET-VM command

    Posted Apr 26, 2019 07:32 PM

    It depends what exactly you want to include in the report.

    There are some metrics on CPU and memory available in the VirtualMachineQuickStats object.
    If you want other metrics over another time period, you will have to call the PerformanceManager with the the Get-Stat cmdlet.