VMware Cloud Community
guy314567
Enthusiast
Enthusiast

PowerCLI script get data from VMX file

Hello PowerCLI experts

im using Vmware Vcenter6

is there a way using powercli script that i can get a list of all VM's machines in Vcenter that has a parameter in sched.mem.minsize = "0"  greatre then "0" in the VMX file?

Thanks!

Reply
0 Kudos
7 Replies
LucD
Leadership
Leadership

Reply
0 Kudos
guy314567
Enthusiast
Enthusiast

Hi Lucd

thanks for your answer!

i have 2 questions:

1. i have 10 datastores, does this script knows to search them all?

2. regarding the correct argument for my purposes, is that the correct syntax for me:

$tgtString = 'sched.mem.minsize = "0" = ">1"'


the goal is to find a vm that has memory reservation greater then 1MB...


Thanks!

Reply
0 Kudos
LucD
Leadership
Leadership

1) The script uses the path of the VMX file, it the datastores are accessible, that shouldn't be a problem.

2) No, you should read the string, then extract the value and compare the extracted value


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

Reply
0 Kudos
LucianoPatrão

Hi,

With this small script you can check all VMs and list all that have the reservation bigger then 0

$Cluster = Get-Cluster "Cluster test"

$VMs = $Cluster | Get-VM

foreach ($VM in $VMs)

{

    $vmview = $vm | get-view

    $VMmem = $vmview.summary.config.MemoryReservation

        if ($VMmem -ge '1')

        {

        Write-Host "VM Name:" -foreground DarkBlue -nonewline; Write-Host " " $vm -foreground DarkGray -nonewline; Write-Host " - Reservation is " -foreground DarkBlue -nonewline; Write-Host $VMmem -foreground DarkGray

        }

   

}

Hope this can help

Luciano Patrão

VCP-DCV, VCAP-DCV Design 2023, VCP-Cloud 2023
vExpert vSAN, NSX, Cloud Provider, Veeam Vanguard
Solutions Architect - Tech Lead for VMware / Virtual Backups

________________________________
If helpful Please award points
Thank You
Blog: https://www.provirtualzone.com | Twitter: @Luciano_PT
Reply
0 Kudos
guy314567
Enthusiast
Enthusiast

is it possible to not give a direct path to one vmx at a time and instead to search vmx in all datastores available?

Reply
0 Kudos
LucD
Leadership
Leadership

Yes, that would require the use of the SearchDatastoreSubFolders on the HostDatastoreBrowser, there you can specify a filter to look for all VMX files (VmConfigFileQuery).


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

Reply
0 Kudos
guy314567
Enthusiast
Enthusiast

thanks but im looking for a way to look in the vmx file because there is a known issue that sometimes the vmx file is configured with reservation but you cannot see it in the vsphere client or web client and the script that you provided will not show it

Reply
0 Kudos