Get-VMInfoCustom.ps1
19 Sep 2025Description
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.
Usage
Example 1
Get-VMInfoCustom -ServerName "VM1"
Retrieves information about the virtual machine with the name “VM1”.
Notes
No additional notes.
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 } }
}
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.