Skip to content

Get-HyperVHostInfo

Hyper-V: Retrieves properties of a Hyper-V host

#Requires -Version 5.1
#Requires -Modules Hyper-V

[CmdletBinding()]
Param (
    [string]$ComputerName = "localhost",

    [PSCredential]$Credential,

    [string[]]$Properties = @('ComputerName', 'VirtualHardDiskPath', 'VirtualMachinePath', 'LogicalProcessorCount', 'MemoryCapacity', 'MacAddressMinimum', 'MacAddressMaximum', 'FullyQualifiedDomainName')
)

Process {
    try {
        if ($Properties -contains '*') {
            $Properties = @('*')
        }

        $params = @{
            'ComputerName' = $ComputerName
            'ErrorAction'  = 'Stop'
        }
        if ($Credential) { $params.Add('Credential', $Credential) }

        $hostInfo = Get-VMHost @params
        $result = $hostInfo | Select-Object $Properties

        Write-Output $result
    }
    catch {
        throw
    }
}

Specifies the name of the Hyper-V host. Defaults to the local machine.

Specifies the credentials to use for the remote connection.

Optional. Specifies an array of properties to retrieve. Defaults to standard administrative properties. Use '*' for all.

An interactive directory of PowerShell scripts.