Check Azure Defender Status on Azure Subscription with PowerShell

4 Min. Read

During Microsoft Ignite in November 2021, Azure Security Center and Azure Defender are now called Microsoft Defender for Cloud. They’ve also renamed Azure Defender plans to Microsoft Defender plans. For example, Azure Defender for Storage is now Microsoft Defender for Storage.

In this article, we will share with you how to check Azure Defender status (formerly known as the Standard Tier in Azure Security Center) on every Azure subscription with PowerShell.

Introduction

Azure Security Center gives you complete visibility and control over the security of hybrid cloud workloads, including compute, network, storage, identity, and application workloads. Azure Security Center (ASC) has two main value propositions:

1) Cloud Security Posture Management (CSPM) – Help you prevent misconfiguration to strengthen your security posture for all different types of cloud workloads and resources in Azure (IaaS, PaaS, and SaaS). CSPM in Security Center is available for free to all Azure users.

2) Cloud Workload Protection Platform (CWPP) – Protect against threats for servers whether they are running in Azure, on-premises, or different clouds such as Amazon AWS or Google GCP, in addition to cloud-native workloads such as Web Apps, Kubernetes, Key Vaults, as well as for SQL databases (PaaS/VM) and storage accounts. CWPP is part of the Azure Defender plan (formerly known as the Standard Tier).

Azure Defender is an evolution of the threat-protection technologies in Azure Security Center, protecting Azure and hybrid environments. When you enable Azure Defender from the Pricing and settings area of Azure Security Center, the following Defender plans are all enabled simultaneously and provide comprehensive defenses for the compute, data, and service layers of your environment:

From the Environment settings area, you can also enable or disable one of the Azure Defender plans as shown in the figure below.

Check Azure Defender Status on Azure Subscription with PowerShell 1

What if you have many subscriptions and you want to know which Azure Defender plan is enabled on which subscription?

In this quick article, we will share with you how to query Azure Defender on every Azure subscription and get its status with PowerShell.

Prerequisites

To follow this article, you need to have the following:

1) Azure subscription – If you don’t have an Azure subscription, you can create a free one here.

2) Azure Security Center Free or Azure Defender enabled.

3) Azure PowerShell installed locally on your machine or using Azure Cloud Shell.

4) The Azure Resource Graph module for PowerShell. Please note that this module can be used with locally installed PowerShell, with Azure Cloud Shell, or with the PowerShell Docker image.

Install Azure Resource Graph module

In this example, I am using the Azure Cloud Shell. Open the Cloud Shell and run the following commands to install the Azure Resource Graph module from PowerShell Gallery.

# Install the Resource Graph module from PowerShell Gallery
Install-Module -Name Az.ResourceGraph
# Get a list of commands for the imported Az.ResourceGraph module
Get-Command -Module 'Az.ResourceGraph' -CommandType 'Cmdlet'

At the time of this writing, I am running the latest Resource Graph PowerShell version (0.7.7).

Check Azure Defender Status on Azure Subscription with PowerShell 2

Get Microsoft Defender status

Assuming you have all the prerequisites in place, open the Azure Cloud Shell (https://shell.azure.com/) and run the following command:

# Query Azure Defender Status and sort by tier
Search-AZGraph -Query "securityresources | where type == `"microsoft.security/pricings`" | extend tier = properties.pricingTier | project name, tier, subscriptionId" | Sort-object tier

In my example, the output looks like this. You can see the name of each Azure Defender plan if it’s enabled (Standard), or not (Free). The Standard tier is still referred to as the old naming, I believe that Microsoft will change it to Microsoft Defender in the future (the subscription Id has been intentionally obscured in this example).

Check Azure Defender Status on Azure Subscription with PowerShell 3

For small to medium deployment, you could use the Azure PowerShell or CLI as described in this article. However, it is not a good idea to do it on a large scale because Azure Resource Manager (ARM) will throttle requests at 12k/h.

For large-scale deployment with a lot of subscriptions, it’s recommended to use the Azure Resource Graph (ARG) explorer.

Open the Azure Resource Graph Explorer blade and run the following KQL query:

securityresources
| where type == "microsoft.security/pricings"
| project DefenderPlan=name, subscriptionId, Pricing = properties.pricingTier
| order by DefenderPlan asc

Here are the output and results of the query:

Query Microsoft Defender for Cloud plan for all subscriptions with Azure Resource Graph
Query Microsoft Defender for Cloud plan for all subscriptions with Azure Resource Graph

That’s it there you have it!

There’s more…

You could also get Microsoft Defender for Cloud status plan using PowerShell and the Azure CLI.

Azure PowerShell

# Set the Azure context for the relevant subscription
Set-AzContext -Subscription "xxxx-xxxx-xxxx-xxxx"

# Show Microsoft Defender for Cloud plan
Get-AzSecurityPricing | select Name, PricingTier, FreeTrialRemainingTime
Show Microsoft Defender for Cloud plan with PowerShell
Show Microsoft Defender for Cloud plan with PowerShell

Azure CLI

# Set the Azure context for the relevant subscription
az account set --subscription "xxxx-xxxx-xxxx-xxxx"

# Show Defender for Storage plan
az security pricing list --query "value[*].{DefenderPlan:name,Pricing:pricingTier,RemainingTime:freeTrialRemainingTime}" --output table
Show Microsoft Defender for Cloud plan with Azure CLI
Show Microsoft Defender for Cloud plan with Azure CLI

Summary

In this article, we showed you how to query Azure Defender status on every Azure subscription with PowerShell and Azure Resource Graph.

Additional resources we highly encourage you to check:

__
Thank you for reading my blog.

If you have any questions or feedback, please leave a comment.

-Charbel Nemnom-

Related Posts

Previous

How to Configure Application Gateway in Front of Azure Blob Storage

Finding Diagnostic Settings Configuration for Azure Resources

Next

3 thoughts on “Check Azure Defender Status on Azure Subscription with PowerShell”

Leave a comment...

  1. How come I only get a handful of results when running the below command?

    Search-AZGraph -Query “securityresources | where type == `”microsoft.security/pricings`” | extend tier = properties.pricingTier | project name, tier, subscriptionId”

    I’m supposed to query 600+ subs but I’m only getting 100+ in my results.

  2. Hello Soper, thanks for the comment!
    It looks like you’ve been throttled by the Azure Resource Manager (reads/12K).
    A better way is to use Azure Resource Graph Explorer here, and then run the query below:

    securityresources
    | where type == "microsoft.security/pricings"
    | project DefenderPlan=name, subscriptionId, Pricing = properties.pricingTier
    | order by DefenderPlan asc

    It should work in your large environment.
    Hope it helps!

Let me know what you think, or ask a question...

The content of this website is copyrighted from being plagiarized!

You can copy from the 'Code Blocks' in 'Black' by selecting the Code.

Please send your feedback to the author using this form for any 'Code' you like.

Thank you for visiting!