Home > Software engineering >  How to pass item in array item to powershell command that uses a filter
How to pass item in array item to powershell command that uses a filter

Time:06-18

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

CodePudding user response:

Have you tried enclosing your variable in single quotes?

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

https://docs.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'"
}
  • Related