VMware Cloud Community
TICTOC201110141
Enthusiast
Enthusiast
Jump to solution

Script running realy slow

I need VM Name  Host Cluster and Operating system so I cobbled this together. Works but is slower than slow. What can I change to speed it up some?

Get-VM | Select Name,@{N=”ESX Host”;E={Get-VMHost -VM $_}}, @{N=”Cluster Name”;E={Get-Cluster -VM $_}}, @{N="Operating System";E={$_.ExtensionData.Guest.guestFullName}} | Export-Csv C:\REPORTS\MYREPORT.CSV

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The Get-View cmdlet gives you direct access to the methods and properties of the vSphere object (as documented in the API Reference

Since the cmdlet doesn't have the overhead of constructing the .Net objects, it tends to be considerable faster (especially in larger environments).

The error you mention doesn't ring a bell.

Could it that something went wrong in the copy of the script from the webpage ?

I'll attach the script as a file to exclude that possible problem


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

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this

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

Select Name,

    @{N=”ESX Host”;E={Get-View -Id $_.Runtime.Host -Property Name | Select -ExpandProperty Name}},

    @{N='Cluster Name';E={

        $parent = Get-View -Id $_.Runtime.Host -Property Name,Parent

        while($parent -isnot [VMware.Vim.ClusterComputeResource] -and $parent.Parent){

            $parent = Get-View -Id $parent.Parent -Property Name,Parent

        }

        $parent | Select -ExpandProperty Name

    }},

    @{N='Operating System';E={$_.Guest.GuestFullName}} | 

Export-Csv "C:\TEMP\MemoryRation.csv" -noTypeInformation -UseCulture


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

Reply
0 Kudos
TICTOC201110141
Enthusiast
Enthusiast
Jump to solution

I see how you broke down each segment but I am new the Get-View, though  I am finding it much better at finding info I need, now though I get

The term 'â??ESX' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

At C:\scripts\vminfo_02.ps1:3 char:15

Not sure why @{N=”ESX Host”;E= would bother anything ...

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The Get-View cmdlet gives you direct access to the methods and properties of the vSphere object (as documented in the API Reference

Since the cmdlet doesn't have the overhead of constructing the .Net objects, it tends to be considerable faster (especially in larger environments).

The error you mention doesn't ring a bell.

Could it that something went wrong in the copy of the script from the webpage ?

I'll attach the script as a file to exclude that possible problem


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

Reply
0 Kudos
TICTOC201110141
Enthusiast
Enthusiast
Jump to solution

Thank You!! Just another reason to really start using Get-View is the speed of the scripts. Been just sticking to the what I know but now that I went through hurdles of trying to get Guest-OS information the old way it's nothing but Get-view for me.

Thanks Again!!

Reply
0 Kudos