dekoshal
Hot Shot
Hot Shot

Overhead memory for all VM's

Jump to solution

I am using method mentioned below by william Lam for pulling report of overhead memory. It works great for a single VM however when i try it for all vm's  it just populate

data on the screen and do not export it in the export path file.

http://www.virtuallyghetto.com/2016/01/easily-retrieve-vm-memory-overhead-using-the-vsphere-6-0-api....

Command using for exporting overhead memory for all  the vm's

Get-VM  | Get-VMMemOverhead | Export-Xlsx  -Path D:\overhead.xlsx -WorksheetName HA

It shows the result in the screen but do not export.

Best Regards,

Deepak Koshal

1 Solution

Accepted Solutions
LucD
Leadership
Leadership

William's function takers pipeline input, so you could do

Get-VM | Get-VMMemOverhead

Unfortunately the function sends the output to the console, it doesn't pass an object.

That explains why you get an empty spreadsheet.

With a small adaption you can return the results over the pipeline.

Something like this

Function Get-VMMemOverhead {

    param

    [Parameter(

        Position=0,

        Mandatory=$true,

        ValueFromPipeline=$true,

        ValueFromPipelineByPropertyName=$true)

    ]

    [Alias('FullName')]

    [VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl[]]$VM

    )

    process {

        # Retrieve VM & ESXi MoRef

        $vmMoref = $VM.ExtensionData.MoRef

        $vmHostMoref = $VM.ExtensionData.Runtime.Host

        # Retrieve Overhead Memory Manager

        $overheadMgr = Get-View ($global:DefaultVIServer.ExtensionData.Content.OverheadMemoryManager)

        # Get VM Memory overhead

        $overhead = $overheadMgr.LookupVmOverheadMemory($vmMoref,$vmHostMoref)

        New-Object PSOBject -Property @{

            VM = $VM.Name

            OverheadMB = [math]::Round($overhead/1MB,2)

        }

    }

}

Get-VM | Get-VMMemOverhead | Export-Xlsx  -Path D:\overhead.xlsx -WorksheetName HA


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

View solution in original post

1 Reply
LucD
Leadership
Leadership

William's function takers pipeline input, so you could do

Get-VM | Get-VMMemOverhead

Unfortunately the function sends the output to the console, it doesn't pass an object.

That explains why you get an empty spreadsheet.

With a small adaption you can return the results over the pipeline.

Something like this

Function Get-VMMemOverhead {

    param

    [Parameter(

        Position=0,

        Mandatory=$true,

        ValueFromPipeline=$true,

        ValueFromPipelineByPropertyName=$true)

    ]

    [Alias('FullName')]

    [VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl[]]$VM

    )

    process {

        # Retrieve VM & ESXi MoRef

        $vmMoref = $VM.ExtensionData.MoRef

        $vmHostMoref = $VM.ExtensionData.Runtime.Host

        # Retrieve Overhead Memory Manager

        $overheadMgr = Get-View ($global:DefaultVIServer.ExtensionData.Content.OverheadMemoryManager)

        # Get VM Memory overhead

        $overhead = $overheadMgr.LookupVmOverheadMemory($vmMoref,$vmHostMoref)

        New-Object PSOBject -Property @{

            VM = $VM.Name

            OverheadMB = [math]::Round($overhead/1MB,2)

        }

    }

}

Get-VM | Get-VMMemOverhead | Export-Xlsx  -Path D:\overhead.xlsx -WorksheetName HA


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

View solution in original post