VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Missing VMs without VMware Tools

Hi,

The below scripts works where VMware Tools are installed but it is not listing the VMs where VMware Tools are not installed.

Please help.

$VmInfo = Foreach($vc in $global:DefaultVIServers){

ForEach ($VM in Get-Folder Universal-Dev -Server $vc | Get-VM -Server $vc)

{

($VM.Extensiondata.Guest.Disk | Select @{N="Name";E={$VM.Name}},

@{N='vCenter';E={([uri]$vm.ExtensionData.Client.ServiceUrl).Host}},

@{N="IPAddress";E={$VM.guest.IPAddress[0]}},

@{N="VM PowerState";E={@($VM.PowerState)}},

@{N="Operating System"; E={@($VM.guest.OSFullName)}},

@{N="Folder";E={$VM.Folder.Name}},

}

}

$VmInfo

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

That would require a different approach.
Something like this

$vmInfo = Foreach ($vc in $global:DefaultVIServers)

{

    Get-Folder Universal-Dev -Server $vc | Get-VM -Server $vc |

    ForEach-Object -Process {

        $obj = [HashTable]::new()

        $obj.Add('Name', $_.Name)

        $obj.Add('vCenter', ([uri]$_.ExtensionData.Client.ServiceUrl).Host)

        $obj.Add('VM PowerState', $_.PowerState)

        $obj.Add('Folder', $_.Folder.Name)

        $obj.Add('IPAddress', '')

        $obj.Add('Mountpoint', '')

        $obj.Add('Capacity(GB)', '')

        $obj.Add('FreeSpace(GB)', '')

        $obj.Add('FreeSpace(%)', '')

        $obj.Add('UsedSpace(GB)', '')


        $vmg = Get-VMGuest -VM $_

        if ($vmg.Disks)

        {

            $vmg.Disks | ForEach-Object -Process {

                $t = $obj.Clone()

                $t.IPAddress = $vmg.IPAddress[0]

                $t.Mountpoint = $_.Path

                $t."Capacity(GB)" = [math]::Round($_.Capacity / 1GB)

                $t."FreeSpace(GB)" = [math]::Round($_.FreeSpace / 1GB)

                $t."FreeSpace(%)" = [math]::Round(((100 * ($_.FreeSpace)) / ($_.Capacity)), 0)

                $t."UsedSpace(GB)" = [math]::Round(((($_.Capacity / 1GB)) - ($_.FreeSpace / 1GB)), 0)

                New-Object PSObject -Property $t

            }

        }

        else

        {

            New-Object PSObject -Property $obj

        }

    }

}

$vmInfo |

Select Name, vCenter, 'VM PowerState', Folder, IPAddress, Mountpoint, 'Capacity(GB)', 'FreeSpace(GB)', 'FreeSpace(%)', 'UsedSpace(GB)'


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

View solution in original post

Reply
0 Kudos
10 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this

$VmInfo = Foreach ($vc in $global:DefaultVIServers) {

  Get-Folder Universal-Dev -Server $vc | Get-VM -Server $vc |

  Select Name,

      @{N = 'vCenter'; E = { ([uri]$_.ExtensionData.Client.ServiceUrl).Host } },

      @{N = "IPAddress"; E = { $_.guest.IPAddress[0] } },

      @{N = "VM PowerState"; E = { @($_.PowerState) } },

      @{N = "Operating System"; E = { @($_.guest.OSFullName) } },

      @{N = "Folder"; E = { $_.Folder.Name } }

}

$VmInfo


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

After modifying, Mountpoint, Capacity, Freespace, Usedspace shows blank

$VmInfo = Foreach ($vc in $global:DefaultVIServers) {

Get-Folder Universal-Dev -Server $vc | Get-VM -Server $vc |

Select Name,

@{N='vCenter';E={([uri]$_.ExtensionData.Client.ServiceUrl).Host}},

@{N="IPAddress";E={$_.guest.IPAddress[0]}},

@{N="VM PowerState";E={@($_.PowerState)}},

@{N="Operating System";E={@($_.guest.OSFullName)}},

@{N="Folder";E={$_.Folder.Name}},

@{N="MountPoint";E={$_.DiskPath}},

@{N="Capacity(GB)";E={[math]::Round($_.Capacity/ 1GB)}},

@{N="FreeSpace(GB)";E={[math]::Round($_.FreeSpace / 1GB)}},

@{N="FreeSpace(%)";E={[math]::Round(((100* ($_.FreeSpace))/($_.Capacity)),0)}},

@{N="UsedSpace(GB)";E={[math]::Round(((($_.Capacity / 1GB))-($_.FreeSpace / 1GB)),0)}}

}

$VmInfo

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Those properties were not in your original script.
And they of course need a different script.
The following is one way of displaying the data

$VmInfo = Foreach ($vc in $global:DefaultVIServers) {

  Get-Folder Universal-Dev -Server $vc | Get-VM -Server $vc |

  Get-VMGuest |

  Select @{N='Name';E={$_.Vm.Name}},

      @{N = 'vCenter'; E = { ([uri]$_.Vm.ExtensionData.Client.ServiceUrl).Host } },

      @{N = "IPAddress"; E = { $_.IPAddress[0] } },

      @{N = "VM PowerState"; E = { @($_.Vm.PowerState) } },

      @{N = "Operating System"; E = { @($_.OSFullName) } },

      @{N = "Folder"; E = { $_.Vm.Folder.Name } },

      @{N="MountPoint";E={$_.Disks.Path -join '|'}},

      @{N="Capacity(GB)";E={($_.Disks.Capacity | %{[math]::Round($_/ 1GB)}) -join '|'}},

      @{N="FreeSpace(GB)";E={($_.Disks.FreeSpace | %{[math]::Round($_ / 1GB)}) -join '|'}},

      @{N="FreeSpace(%)";E={($_.Disks | %{[math]::Round(((100* ($_.FreeSpace))/($_.Capacity)),0)}) -join '|'}},

      @{N="UsedSpace(GB)";E={($_.Disks | %{[math]::Round(((($_.Capacity / 1GB))-($_.FreeSpace / 1GB)),0)}) -join '|'}}    

}

$VmInfo


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

I am getting the Mountpoint, Capacity and other in single line, But I would like to get in different lines,

I tried as below, but not working

$VmInfo = Foreach ($vc in $global:DefaultVIServers) {

  Get-Folder Universal-Dev -Server $vc | Get-VM -Server $vc |

  Get-VMGuest |

  Select @{N='Name';E={$_.Vm.Name}},

      @{N = 'vCenter'; E = { ([uri]$_.Vm.ExtensionData.Client.ServiceUrl).Host } },

      @{N = "IPAddress"; E = { $_.IPAddress[0] } },

      @{N = "VM PowerState"; E = { @($_.Vm.PowerState) } },

      @{N = "Operating System"; E = { @($_.OSFullName) } },

      @{N = "Folder"; E = { $_.Vm.Folder.Name } },

      @{N="MountPoint";E={$_.Disks.Path}},

      @{N="Capacity(GB)";E={[math]::Round($_.Disks.Capacity/ 1GB)}},

      @{N="FreeSpace(GB)";E={[math]::Round($_.Disks.FreeSpace / 1GB)}},

      @{N="FreeSpace(%)";E={[math]::Round(((100* ($_.Disks.FreeSpace))/($_.Disks.Capacity)),0)}},

      @{N="UsedSpace(GB)";E={[math]::Round(((($_.Disks.Capacity / 1GB))-($_.Disks.FreeSpace / 1GB)),0)}}

}

$VmInfo

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

If you want each mount point on a different line, you are going to have redundant data (appearing in each row).

Something like this

$VmInfo = Foreach ($vc in $global:DefaultVIServers) {

    Get-Folder Universal-Dev -Server $vc | Get-VM -Server $vc |

    Get-VMGuest | ForEach-Object -Process {

        $vmg = $_

        $vmg.Disks | Select @{N='Name';E={$vmg.Vm.Name}},

        @{N = 'vCenter'; E = { ([uri]$vmg.Vm.ExtensionData.Client.ServiceUrl).Host } },

        @{N = "IPAddress"; E = { $vmg.IPAddress[0] } },

        @{N = "VM PowerState"; E = { @($vmg.Vm.PowerState) } },

        @{N = "Operating System"; E = { @($vmg.OSFullName) } },

        @{N = "Folder"; E = { $vmg.Vm.Folder.Name } },

        @{N="MountPoint";E={$_.Path}},

        @{N="Capacity(GB)";E={[math]::Round($_.Capacity/ 1GB)}},

        @{N="FreeSpace(GB)";E={[math]::Round($_.FreeSpace / 1GB)}},

        @{N="FreeSpace(%)";E={[math]::Round(((100* ($_.FreeSpace))/($_.Capacity)),0)}},

        @{N="UsedSpace(GB)";E={[math]::Round(((($_.Capacity / 1GB))-($_.FreeSpace / 1GB)),0)}}

  }

}

$VmInfo


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

The script works where VMware Tools are installed but it is not listing the VMs where VMware Tools are not installed or not working.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Which is normal since Get-VMGuest requires VMware Tools for most of the properties.

What do you want to display when the VMware Tools are not installed or running?


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

I would like to get the VM Name listed in the report, even if VMware Tools are not installed with the blank fields.

Currently, I will miss on the VMs where VMware Tools is not installed or running. It would be difficult, which VM I need to gather disk info manually.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That would require a different approach.
Something like this

$vmInfo = Foreach ($vc in $global:DefaultVIServers)

{

    Get-Folder Universal-Dev -Server $vc | Get-VM -Server $vc |

    ForEach-Object -Process {

        $obj = [HashTable]::new()

        $obj.Add('Name', $_.Name)

        $obj.Add('vCenter', ([uri]$_.ExtensionData.Client.ServiceUrl).Host)

        $obj.Add('VM PowerState', $_.PowerState)

        $obj.Add('Folder', $_.Folder.Name)

        $obj.Add('IPAddress', '')

        $obj.Add('Mountpoint', '')

        $obj.Add('Capacity(GB)', '')

        $obj.Add('FreeSpace(GB)', '')

        $obj.Add('FreeSpace(%)', '')

        $obj.Add('UsedSpace(GB)', '')


        $vmg = Get-VMGuest -VM $_

        if ($vmg.Disks)

        {

            $vmg.Disks | ForEach-Object -Process {

                $t = $obj.Clone()

                $t.IPAddress = $vmg.IPAddress[0]

                $t.Mountpoint = $_.Path

                $t."Capacity(GB)" = [math]::Round($_.Capacity / 1GB)

                $t."FreeSpace(GB)" = [math]::Round($_.FreeSpace / 1GB)

                $t."FreeSpace(%)" = [math]::Round(((100 * ($_.FreeSpace)) / ($_.Capacity)), 0)

                $t."UsedSpace(GB)" = [math]::Round(((($_.Capacity / 1GB)) - ($_.FreeSpace / 1GB)), 0)

                New-Object PSObject -Property $t

            }

        }

        else

        {

            New-Object PSObject -Property $obj

        }

    }

}

$vmInfo |

Select Name, vCenter, 'VM PowerState', Folder, IPAddress, Mountpoint, 'Capacity(GB)', 'FreeSpace(GB)', 'FreeSpace(%)', 'UsedSpace(GB)'


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Perfect LucD, Thank you very very much Smiley Happy

Reply
0 Kudos