Jona187
Jona187

Reputation: 55

How to pass item in array item to powershell command that uses a filter

accounts=$(az ad sp list --show-mine --query [].appDisplayName -otsv)

This will give me an array

I want to pass each item to an array in this command

foreach ($myApp in $accounts){
Get-AzureADApplication -Filter "DisplayName eq $myApp"
}

When I try this I get syntax error at position is this even possible

I'm a noob to powershell

Upvotes: 1

Views: 123

Answers (1)

BrettMiller
BrettMiller

Reputation: 1046

Have you tried enclosing your variable in single quotes?

According to the documentation the value in the filter is quoted:

https://learn.microsoft.com/en-us/powershell/module/azuread/get-azureadapplication?view=azureadps-2.0#example-1-get-an-application-by-display-name

foreach ($myApp in $accounts){
    Get-AzureADApplication -Filter "DisplayName eq '$myApp'"
}

Upvotes: 4

Related Questions