Currently I'm having a strange problem using the PowerCLI Api from VMware.
I wrote a function that needs an VMware.VimAutomation.Vds.Impl.V1.VmwareVDPortgroupImpl
Object as parameter, but every time I provide such an object it errors out.
While debugging, I found that not even assigning this Object to another Variable with the same type.
PS vi:\IX-eShelter> [VMware.VimAutomation.Vds.Impl.V1.VmwareVDPortgroupImpl]$t = Get-VDPortgroup -Name "dv-test-vlan" | Get-Member
Unable to find type [VMware.VimAutomation.Vds.Impl.V1.VmwareVDPortgroupImpl].
At line:1 char:1
+ [VMware.VimAutomation.Vds.Impl.V1.VmwareVDPortgroupImpl]$t = Get-VDPo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (VMware.VimAutom...VDPortgroupImpl:TypeName) [], RuntimeExc
eption
+ FullyQualifiedErrorId : TypeNotFound
I already tried the following:
[System.Reflection.Assembly]::LoadWithPartialName("VMware.VimAutomation.Vds.Impl.V1.VmwareVDPortgroupImpl")
Add-Type -AssemblyName "VMware.VimAutomation.Vds.Impl"
Edit: My Function:
function New-VMDeployment {Param([Parameter(Mandatory=$true,ValueFromPipeline=$false,ValueFromPipelineByPropertyName=$true)][VMware.VimAutomation.Vds.Impl.V1.VmwareVDPortgroupImpl]$port)
Write-Host $port;
};
I'm calling it like that:
$deployment = [PSCustomObject]@{ "port" = Get-VDPortgroup -Name "dv-test-vlan";};
$deployment | New-VMDeployment;
Looks like the implementation (Impl) type has broken for distributed port groups. You should be able to switch over to the Types type and find it operational.
I would suggest modifying the function to read like:
function New-VMDeployment {
param(
[Parameter(
Position=0,
Mandatory=$true,
ValueFromPipeline=$false,
ValueFromPipelineByPropertyName=$true)
]
[VMware.VimAutomation.Vds.Types.V1.VmwareVDPortgroup]$port
)
Write-Host $port
}
Additional information: https://blogs.vmware.com/PowerCLI/2016/04/powercli-best-practice-correct-use-strong-typing.html