Building a dynamic array of hastables

Welcome Forums General PowerShell Q&A Building a dynamic array of hastables

Viewing 2 reply threads
  • Author
    Posts
    • #212760
      Participant
      Topics: 1
      Replies: 1
      Points: -4
      Rank: Member

      I’m working with a powershell function that looks like the following:

      set-ceblueprint
      -InstanceId $machine.id
      -InstanceType "t3.2xlarge"
      -SubnetIDs "subnet-0d94c365043c93ac8"
      -SecurityGroupIDs "sg-0836f28e55dd2c349"
      -Disks @(@{type = "SSD"; name = "c:0"}, @{type="SSD"; name = "e:0"})
      -Tags @{Environment = "prddr"; ITOwner = "Platform Engineering"; BusinessOwner = "IT"; ManagedBy = "CloudEndure"; ProjectCode = "Support-DR"}

      [/crayon]

      -InstanceId $machine.id

      -InstanceType “t3.2xlarge”
      -SubnetIDs “subnet-0d94c365043c93ac8”

      -SecurityGroupIDs “sg-0836f28e55dd2c349”
      -Disks $diskhash

      -Tags @{Environment = “prddr”; ITOwner = “Platform Engineering”; BusinessOwner = “IT”; ManagedBy = “CloudEndure”; ProjectCode = “Support-DR”}
      -confirm:$false
      }

      The cmdlet doesn’t like the input for $diskhash Hoping for some guidance here, a bit of a newb and am struggling to come up with correct method to use.

      • This topic was modified 10 months ago by Duane Haas.
    • #212787
      Participant
      Topics: 6
      Replies: 667
      Points: 97
      Helping Hand
      Rank: Member

      From what I can tell you are not meeting your own requirement.  You said that -disk needs an array of hash, not a single hash.  When you go through your foreach loop you are just building a hash called $diskhash.  You are not building an array of $diskhash’es.

      IE

    • #212799
      Participant
      Topics: 1
      Replies: 1
      Points: -4
      Rank: Member

      Apologies for the crap formatting, I was able to figure it out:

      $numberofdisks = $machine.sourceProperties.disks
      $diskArray = [System.Collections.Generic.List[hashtable]]@()
      foreach ($disk in $numberofdisks) {

      $diskArray.Add(@{
      name = $disk.name
      type = “SSD”
      })
      }

      Thanks for the time @curtis

Viewing 2 reply threads
  • The topic ‘Building a dynamic array of hastables’ is closed to new replies.