- This topic has 3 replies, 2 voices, and was last updated 2 months, 1 week ago by
Senior Moderator.
Viewing 3 reply threads
-
AuthorPosts
-
-
October 14, 2020 at 6:35 am #263241
Hello, I am using Pester with the Assert module. I am using the following code, which fails:
PowerShell123456789101112# 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?
-
October 14, 2020 at 10:30 am #263298
Just define the variable like below. You have to expand the property get the string type of each.
PowerShell1$global:existing_subnets_of_vnet_01 = (Get-AzVirtualNetwork -name data_vnet_01).subnets | Select-Object -ExpandProperty Name -
November 18, 2020 at 4:46 am #272344
I forgot to also reply to this thread. This has been also solved. Thnx again 🙂
-
November 19, 2020 at 1:30 am #272545
Thanks for letting us know.
-
-
AuthorPosts
Viewing 3 reply threads
- The topic ‘Hashtables comparison (one has PSObjects the other doesnt)’ is closed to new replies.