As well as using GetType(), I often pipe an object through Convertto-json (sometimes having to add -depth) to visualise an object. Pipe that into scb (alias for Set-Clipboard) and paste into notepad for an easier experience than in a console window.
Original Message:
Sent: Jun 21, 2024 02:24 PM
From: LucD
Subject: Why can I not filter an object by property when property equals "xyz"?
Console output is most of the time not the best way to try and determine what is actually returned.
PS uses these formatting files (.PS1XML) to determine what is shown in the console for an object.
Always the GetType() method to determine an object's type.
------------------------------
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Original Message:
Sent: Jun 20, 2024 04:51 AM
From: JDMils_Interact
Subject: Why can I not filter an object by property when property equals "xyz"?
Thanks for that. I was running the command from the command line and got this:
PS > Get-VDPort -VDSwitch $oSwitchObject.Name | Select *ExtensionData : VMware.Vim.DistributedVirtualPortKey : 5Description : IsBlocked : FalseIsBlockedInherited : TrueIsLinkUp : TrueMacAddress : 00:50:56:a0:fb:76VlanConfiguration : VLAN 100ConnectedEntity : Network adapter 1ProxyHost : MyHost15.MyDomain.ComPortgroup : Management100Switch : dvSwitch-MySwitchName : Id : 5Uid : /VIServer=MyDomain\jmilano@MyvCenter:443/DistributedPort=5/
From the result, it seemed that ProxyHost was a text property not an object.
I ran the code in my Powershell ISE and it does come back as an object.
Thank you.
Original Message:
Sent: Jun 20, 2024 03:19 AM
From: LucD
Subject: Why can I not filter an object by property when property equals "xyz"?
Because the ProxyHost property is not a single String but a VMware.VimAutomation.Vds.Types.V1.VDPort object.
To use the -eq operand, use the Name property of the ProxyHost object.
Get-VDPort -VDSwitch $oSwitchObject.Name | where-object { ($_.proxyhost.Name -eq $esxihost.name) } | Select *
------------------------------
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Original Message:
Sent: Jun 19, 2024 10:53 PM
From: JDMils_Interact
Subject: Why can I not filter an object by property when property equals "xyz"?
I cannot get the following code to only return results based on the host name:
PS>$ESXiHost = get-vmhost 'MyHost15.MyDomain.Com'PS>$esxihost.nameMyHost15.MyDomain.ComPS>$oSwitchObject = Get-VirtualSwitch -Name 'MyDVSwitch' -DistributedPS> $oSwitchObjectName NumPorts Mtu Notes---- -------- --- -----MyDVSwitch 782 9000
I have checked that the host is attached to the mentioned dvSwitch using the vCenter GUI.
Now to return the VDPort information for only this host:
Get-VDPort -VDSwitch $oSwitchObject.Name | where-object { ($_.proxyhost -eq $esxihost.name) } | Select *Get-VDPort -VDSwitch $oSwitchObject.Name | where-object { ($_.proxyhost -eq 'MyHost15.MyDomain.Com') } | Select *
HOWEVER, the following commands DO work:
Get-VDPort -VDSwitch $oSwitchObject.Name | where-object { ($_.proxyhost -like $esxihost.name) } | Select *Get-VDPort -VDSwitch $oSwitchObject.Name | where-object { ($_.proxyhost -like 'MyHost15.MyDomain.Com') } | Select *
Why does "-Like" work and not "-eq"?
This is the output of the working commands:
ExtensionData : VMware.Vim.DistributedVirtualPortKey : 9Description :IsBlocked : FalseIsBlockedInherited : TrueIsLinkUp : FalseMacAddress :VlanConfiguration : VLAN 1234ConnectedEntity : Network adapter 1ProxyHost : MyHost15.MyDomain.ComPortgroup : vLAN1234Switch : MySwitchName :Id : 9Uid : /VIServer=MyDomain\jmilano@MyvCenter:443/DistributedPort=9/