I am experiencing and issue where I have created a function:
function Get-VMMemoryReservation
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true,Position=0,ValueFromPipelineByPropertyName=$true)]
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl[]]$VM
)
BEGIN {}
PROCESS
{
foreach ($item in $VM)
{
$VMResourceConfig = $item | Get-VMResourceConfiguration
$Hash = [ordered]@{'ComputerName' = $item.Name;
'AllLocked' = $item.ExtensionData.Config.MemoryReservationLockedToMax;
'ReservationGB' = $VMResourceConfig.MemReservationGB;
'ShareLevel' = $VMResourceConfig.MemSharesLevel;
'Shares' = $VMResourceConfig.NumMemShares }
New-Object -TypeName PSObject -Property $Hash
}
}
END {}
}
When execute the function I get the following error:
Get-VMMemoryReservation : Cannot process argument transformation on parameter 'VM'. Cannot convert the
"Server1" value of type "VMware.VimAutomation.ViCore.Impl.V1.VM.UniversalVirtualMachineImpl" to type
"VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl[]".
At line:1 char:32
+ Get-VMMemoryReservation -VM $ctx
+ ~~~~
+ CategoryInfo : InvalidData: (:) [Get-VMMemoryReservation], ParameterBindingArgumentTransformationExc
eption
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-VMMemoryReservation
This function accepts an Object of VM type VirtualMachineImpl which up until now is the VM Object Type. However in the latest version PowerCLI 6.3 Release 1 that type has changed to UniversalVirtualMachineImpl. A few questions: 1. Why and in which version did the type change, and 2. is there a better way to accept an object of VM Type while being backward compatible with VirtualMachineImpl Type? I have may cmdlets I have created with this type for the input parameters. Thanks for any input you can give.
Have a look at PowerCLI Best Practice: Correct Use of Strong Typing.
That explains what you are seeing I think, and also explains why it is happenig.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Have a look at PowerCLI Best Practice: Correct Use of Strong Typing.
That explains what you are seeing I think, and also explains why it is happenig.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Perfect, thank you very much. I will adjust accordingly.