Hi,
I have some basic PowerCLI skill but want to improve them using more advance features like function, modules and so on.
I want to create PowerShell function which to accept as pipeline VMs object (output from Get-VM).
Very frequently I want to export info about VMs, so I want to simplify this using function.
I write this simple function for this, but there is something wrong with it. Only one VM is display as output. I expect to be many. Where is my mistake.
Example:
Get-Datastore XXX |Get-VM |Info-VM |ft
function Info-VM {
param(
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[VMware.VimAutomation.ViCore.Impl.V1.VM.UniversalVirtualMachineImpl[]]$Entity
)
$Entity | Select @{N="VmName";E={$_.Name} },
PowerState,
@{N="GuestOsHostname";E={$_.Guest.HostName} },
@{N="GuestOsIpAddress"; E={ ( ($_.Guest.IPaddress | where {([IPAddress]$_).AddressFamily -eq [System.Net.Sockets.AddressFamily]::InterNetwork} ) ) -join ", " } },
@{N="EsxHost";E={$_.VMHost } },
@{N="vCPU";E={$_.NumCPU} },
MemoryGB,
@{N="ProvStorageGB"; E={[math]::round($_.ProvisionedSpaceGB,2)}},
@{N="UsedStorageGB"; E={[math]::round($_.UsedSpaceGB,2)}},
Notes,
@{N="OsVersion_ReportedByTools"; E={$_.Guest.OSFullName } },
@{N="OsVersion_Configure"; E={$_.ExtensionData.Config.GuestFullName} },
@{N="BiosUuid"; E={$_.ExtensionData.Config.UUID} },
@{N="ToolsStatus"; E={$_.ExtensionData.Guest.ToolsRunningStatus} }
$VMInfo
}