Powershell Workflow with nested foreach

Emanuele 31 Reputation points
2022-04-11T08:51:38.16+00:00

Hi all,

i'm writing a script to remove and recreate eventhub and private endpoint on Azure. I'm testing the loop before to proceed but had a problem with nested foreach inside a parallel foreach:

    workflow test-evh
{

$connectionResult = Connect-AzAccount -Identity
$connectionResult


$EvhExclusion = 'myevh'


    $EvhLists = Get-AzEventHubNamespace
    $PendsEvh = Get-AzPrivateEndpoint

    foreach -parallel -ThrottleLimit 10 ($EvhList in $EvhLists)
        {           
        if ($EvhList.Name -notin $EvhExclusion){    
           if ($EvhList.Location -eq "North Europe"){

            foreach ($PendEvh in $PendsEvh)
            {           

            if ($PendEvh.PrivateLinkServiceConnections.GroupIds -eq "namespace" -and $PendEvh.Location -eq "northeurope" -and $PendEvh.PrivateLinkServiceConnections.PrivateLinkServiceId -in $EvhList.Id ){

             Write-Output   $PendEvh.Name

            }


            }

            Write-Output $EvhList.Name

        }
    }
}

}

script work but i got only eventhub namespace. If i run it outside workflow and without parallel, it works and i got both private endpoint and namespace.

What i'm doing wrong?

Thanks

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
{count} votes

1 answer

Sort by: Most helpful
  1. Monalla-MSFT 13,166 Reputation points Moderator
    2022-04-14T15:15:09.23+00:00

    @Emanuele - Thanks for reaching out.

    I believe the location does not have a space in it.

    193221-image.png

    193222-image.png

    Hope this helps. and please feel free to reach out if you have any further questions.

    ------------------------------------------------------------------

    If the above response was helpful, please feel free to "Accept as Answer" and "Upvote" the same so it can be beneficial to the community.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.