Get-VMInfoCustom.ps1


Description

Purpose

Retrieves information about a virtual machine.

Detailed Description

The Get-VMInfoCustom function retrieves information about a virtual machine, such as its name, power state, number of CPUs, memory size, guest operating system, IP address, datastore, and network.

Back to Top

Usage

Example 1

Get-VMInfoCustom -ServerName "VM1"

Retrieves information about the virtual machine with the name “VM1”.

Back to Top

Notes

No additional notes.

Back to Top


Script

<#
.SYNOPSIS
Retrieves information about a virtual machine.

.DESCRIPTION
The Get-VMInfoCustom function retrieves information about a virtual machine, such as its name, power state, number of CPUs, memory size, guest operating system, IP address, datastore, and network.

.PARAMETER ServerName
The name of the virtual machine to retrieve information for.

.EXAMPLE
Get-VMInfoCustom -ServerName "VM1"
Retrieves information about the virtual machine with the name "VM1".

#>

function Get-VMInfoCustom {
    Param(
        [parameter()]
        [string]$ServerName
    )
    Get-View -ViewType VirtualMachine -Filter @{"Name" = "$($ServerName)" } | Select-Object -property Name, @{N = "PowerState"; E = { $_.Runtime.PowerState } }, @{N = "NumCpu"; E = { $_.Config.Hardware.NumCPU } }, @{N = "MemoryMB"; E = { $_.Config.Hardware.MemoryMB } }, @{N = "GuestOS"; E = { $_.Config.GuestFullName } }, @{N = "IPAddress"; E = { ($_.Guest.Net | Where-Object { $_.DeviceConfigId -eq 4000 }).IpAddress } }, @{N = "Datastore"; E = { (Get-View -Id $_.Datastore).Name } }, @{N = "Network"; E = { (Get-View -Id $_.Network).Name } }
}

Back to Top

Download

Please feel free to copy parts of the script or if you would like to download the entire script, simply click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.


Report Issues

You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.

Issue


Back to Top