Azure PowerShell Where-Object

The Where-Object cmdlet in Azure PowerShell helps you to select objects based on certain conditions. I will walk you through all the possible syntaxes and usage with examples in this article.

Azure PowerShell Where-Object

This is the basic syntax of Azure PowerShell Where-Object, as mentioned below.

Syntax-1: Basic Syntax

Get-AzStorageAccount | Where-Object { $_.StorageAccountName -eq  "azureusanew" }

After executing the above command, we got the storage account details named azureusanew successfully as shown below.

Get-AzStorageAccount

Syntax-2: Using wildcard character

The below command will get you the lists of storage accounts whose name starts with “a”.

Get-AzStorageAccount | Where-Object { $_.StorageAccountName -like "a*" }

I got the expected output, as shown below.

azure powershell where object

Syntax-3: Using comparison operators

The PowerShell command below helps you retrieve the lists of storage accounts whose names contain “a”.

Get-AzStorageAccount | Where-Object { $_.StorageAccountName -like "*a*" }

After executing the above command, I got the expected output below.

Azure powershell where-object examples

Syntax-4: Using multiple conditions

We can also add multiple conditions with Where-Object as mentioned below.

Get-AzStorageAccount | Where-Object { $_.StorageAccountName -eq "azureusanew" -and $_.Location -eq "eastus" }

After executing the above command, I got the expected output as shown in the screenshot below.

powershell where-object multiple conditions

Syntax-5: Using date properties

We can also use date properties with Where-Object as mentioned below.

Get-AzStorageAccount | Where-Object { $_.TimeCreated -gt (Get-Date).AddDays(-30) }
PowerShell Where-Object

Syntax-6: Using methods on properties

Get-AzStorageAccount | Where-Object { $_.Tags.Keys -contains "Apple" }

After executing the above command, I got the expected output below.

azure powershell where-object examples with condition

Conclusion

Azure PowerShell Where-Object is crucial to retrieve the objects based on certain conditions as mentioned in this article.

You may also like following the articles below.

Azure Virtual Machine

DOWNLOAD FREE AZURE VIRTUAL MACHINE PDF

Download our free 25+ page Azure Virtual Machine guide and master cloud deployment today!