Skip to content

Instantly share code, notes, and snippets.

@chelnak
Last active August 2, 2016 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chelnak/7fd6f759e7f9548fec40fe94eff3889f to your computer and use it in GitHub Desktop.
Save chelnak/7fd6f759e7f9548fec40fe94eff3889f to your computer and use it in GitHub Desktop.
function Get-VMExtendedInfo {
<#
.SYNOPSIS
Gets extended information about a Virtual Machine
.DESCRIPTION
Gets extended information about a Virtual Machine
.PARAMETER VM
The Virtual Machine to query
.INPUTS
PSObject
.OUTPUTS
System.Management.Automation.PSObject
.EXAMPLE
Get-VM | Get-VMExtendedInfo | Export-Csv -Path .\VMInfo.csv -NoTypeInformation
.EXAMPLE
Get-VM | Get-VMExtendedInfo
.EXAMPLE
Get-VM -Name VM-01 | Get-VMExtendedInfo
#>
[CmdletBinding()][OutputType('System.Management.Automation.PSObject')]
Param (
[parameter(Mandatory=$true, ValueFromPipeline=$true)]
[ValidateNotNullOrEmpty()]
[PSObject[]]$VM
)
begin {}
process{
foreach ($VirtualMachine in $VM) {
$View = $VirtualMachine | Get-View
[URI]$ServiceUrl = $View.Client.ServiceUrl
[PSCustomObject]@{
Name = $VirtualMachine.Name
PowerState = $View.Runtime.PowerState
GuestOSFullName = $View.Guest.GuestFullName
ParentHost = $VirtualMachine.VMHost.Name
ParentvCenter = $ServiceUrl.Host
ParentvCenterFolder = $VirtualMachine.Folder
ParentDatacenter = ($VirtualMachine | Get-Datacenter).Name
NumberOfNics = ($VirtualMachine | Get-NetworkAdapter).Count
}
}
}
end {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment