PowerShell 无法找到类型 [VMware.VimAutomation.Vds.Impl.V1.VmwareVDPortgroupImpl]
PowerShell unable to find type [VMware.VimAutomation.Vds.Impl.V1.VmwareVDPortgroupImpl]
目前我在使用 VMware 的 PowerCLI Api 时遇到了一个奇怪的问题。
我写了一个需要 VMware.VimAutomation.Vds.Impl.V1.VmwareVDPortgroupImpl
对象作为参数的函数,但每次我提供这样的对象时它都会出错。
调试时,我发现甚至没有将此对象分配给另一个具有相同类型的变量。
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
我已经尝试过以下方法:
[System.Reflection.Assembly]::LoadWithPartialName("VMware.VimAutomation.Vds.Impl.V1.VmwareVDPortgroupImpl")
Add-Type -AssemblyName "VMware.VimAutomation.Vds.Impl"
编辑:
我的函数:
function New-VMDeployment {Param([Parameter(Mandatory=$true,ValueFromPipeline=$false,ValueFromPipelineByPropertyName=$true)][VMware.VimAutomation.Vds.Impl.V1.VmwareVDPortgroupImpl]$port)
Write-Host $port;
};
我是这样称呼它的:
$deployment = [PSCustomObject]@{ "port" = Get-VDPortgroup -Name "dv-test-vlan";};
$deployment | New-VMDeployment;
分布式端口组的实现 (Impl) 类型似乎已损坏。您应该能够切换到 Types 类型并发现它可以运行。
我建议将函数修改为:
function New-VMDeployment {
param(
[Parameter(
Position=0,
Mandatory=$true,
ValueFromPipeline=$false,
ValueFromPipelineByPropertyName=$true)
]
[VMware.VimAutomation.Vds.Types.V1.VmwareVDPortgroup]$port
)
Write-Host $port
}
附加信息:https://blogs.vmware.com/PowerCLI/2016/04/powercli-best-practice-correct-use-strong-typing.html
目前我在使用 VMware 的 PowerCLI Api 时遇到了一个奇怪的问题。
我写了一个需要 VMware.VimAutomation.Vds.Impl.V1.VmwareVDPortgroupImpl
对象作为参数的函数,但每次我提供这样的对象时它都会出错。
调试时,我发现甚至没有将此对象分配给另一个具有相同类型的变量。
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
我已经尝试过以下方法:
[System.Reflection.Assembly]::LoadWithPartialName("VMware.VimAutomation.Vds.Impl.V1.VmwareVDPortgroupImpl")
Add-Type -AssemblyName "VMware.VimAutomation.Vds.Impl"
编辑: 我的函数:
function New-VMDeployment {Param([Parameter(Mandatory=$true,ValueFromPipeline=$false,ValueFromPipelineByPropertyName=$true)][VMware.VimAutomation.Vds.Impl.V1.VmwareVDPortgroupImpl]$port)
Write-Host $port;
};
我是这样称呼它的:
$deployment = [PSCustomObject]@{ "port" = Get-VDPortgroup -Name "dv-test-vlan";};
$deployment | New-VMDeployment;
分布式端口组的实现 (Impl) 类型似乎已损坏。您应该能够切换到 Types 类型并发现它可以运行。
我建议将函数修改为:
function New-VMDeployment {
param(
[Parameter(
Position=0,
Mandatory=$true,
ValueFromPipeline=$false,
ValueFromPipelineByPropertyName=$true)
]
[VMware.VimAutomation.Vds.Types.V1.VmwareVDPortgroup]$port
)
Write-Host $port
}
附加信息:https://blogs.vmware.com/PowerCLI/2016/04/powercli-best-practice-correct-use-strong-typing.html