Hashtables comparison (one has PSObjects the other doesnt)

Hello, I am using Pester with the Assert module. I am using the following code, which fails:

# Get subnets of a Vnet
$global:existing_subnets_of_vnet_01 = @(
    ((Get-AzVirtualNetwork -name data_vnet_01).subnets) | Select-Object -property Name
    )
# Compare against expected subnets of a Vnet
$global:expected_subnets_of_vent_01 = “data_subnet_01", “data_subnet_02"

# Then the comparison:
Describe "Vnet/Subnet Config Tests" {
     It "Subnet AddressPrefix & under correct Vnet_01 Test" { 
     Assert-Equivalent -Actual $existing_subnets_of_vnet_01 -Expected $expected_subnets_of_vent_01 #pass
        }

I know the issue is down to 1 of these arrays or hashtable (not sure which), has PSObjects and the other is a string based array. How do I make it so they are both string based so the comparison works?

My followup question is how do I know when an array is an array and an hashtable is a hastable? Can you have an hashtable with just keys with no values or does that automatically make it an array?

Just define the variable like below. You have to expand the property get the string type of each.

$global:existing_subnets_of_vnet_01 = (Get-AzVirtualNetwork -name data_vnet_01).subnets | Select-Object -ExpandProperty Name

I forgot to also reply to this thread. This has been also solved. Thnx again :slight_smile:

Thanks for letting us know.