2

For example, I have 3 hashtables with different key-values:

$Queue1 = @{
    QueueName = 'MyTestQueue1'
    LockDuration = 'PT1M1'
    AutoDeleteOnIdle = 'P10675199DT2H48M5.4775807S1'
}

$Queue2 = @{
    QueueName = 'MyTestQueue2'
    LockDuration = 'PT1M2'
    AutoDeleteOnIdle = 'P10675199DT2H48M5.4775807S2'
}

$Queue3 = @{
    QueueName = 'MyTestQueue3'
    LockDuration = 'PT1M3'
    AutoDeleteOnIdle = 'P10675199DT2H48M5.4775807S3'
}

Is it possible to combine them in the array and use each key-value inside the foreach?

foreach($hashtable in $Hashtables){
    
    $QueueName = $hashtable.QueueName
    $LockDuration = $hashtable.LockDuration 
    $AutoDeleteOnIdle = $hashtable.AutoDeleteOnIdle
    # Some code here
    }
2
  • 1
    How about $Hashtables = @($Queue1, $Queue2, $Queue3), does this work? Commented Mar 24, 2022 at 8:47
  • Thanks! Was unable to find such an example. You can arrange this as the right answer. Commented Mar 24, 2022 at 8:50

1 Answer 1

3

To declare an array, as portrayed here, you use this syntax:

$variable = @(element1, element2, element3, ...)

so to create an array for your queues:

$Hashtables = @($Queue1, $Queue2, $Queue3)

you can also split it over multiple lines, and in that variant the commas are optional:

$Hashtables = @(
    $Queue1
    $Queue2
    $Queue3
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.