Powershell script to disable Security Defaults in Azure Active Directory

Jeanne De Villiers 0 Reputation points
2023-04-30T18:25:06.02+00:00

I am looking after numerous Microsoft 365 Tenants. I am trying to create a Powershell script that I can run to check if Security Defaults are enabled/disabled in Azure Active directory.

Once I know the status, I want to be able to enable/disable Security Defaults in AAD using the powershell script.

Is there anyone that can point me in the right direction. I have come across some solutions but none of them worked.

Microsoft 365 and Office | Install, redeem, activate | For business | Windows
Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Microsoft Entra | Microsoft Entra ID
{count} votes

3 answers

Sort by: Most helpful
  1. Akshay-MSFT 17,961 Reputation points Microsoft Employee Moderator
    2023-05-05T13:55:27.1533333+00:00

    @Jeanne De Villiers

    The other alternative you could use is :

    To validate if security default is enabled or not:

    Connect-MgGraph -Scopes Policy.ReadWrite.ConditionalAccess, Policy.Read.All
    Get-MgPolicyIdentitySecurityDefaultEnforcementPolicy | select IsEnabled
    

    To enable it use the following command:

    $params = @{
    	IsEnabled = $true
    }
    Update-MgPolicyIdentitySecurityDefaultEnforcementPolicy -BodyParameter $params		
    

    To disable it use the following command:

    $params = @{
    	IsEnabled = $true
    }
    Update-MgPolicyIdentitySecurityDefaultEnforcementPolicy -BodyParameter $params
    

    Please do let me know if you have any queries in the comments.

    Thanks,

    Akshay Kaushik

    Please "Accept the answer" (Yes), and share your feedback if the suggestion answers you’re your query. This will help us and others in the community as well.

    1 person found this answer helpful.

  2. Andy David - MVP 157.8K Reputation points MVP Volunteer Moderator
    2023-04-30T18:46:11.6333333+00:00

  3. Jose Ortega 1 Reputation point
    2024-03-29T16:23:16.2766667+00:00

    Requires the module installed previously:

    Set-executionPolicy RemoteSigned
    Install-Module -Name Microsoft.Graph
    Connect-MgGraph -Scopes Policy.ReadWrite.ConditionalAccess, Policy.Read.All
    Get-MgPolicyIdentitySecurityDefaultEnforcementPolicy | select IsEnabled
    

    Now we can talk, To disable

    $params = @{ IsEnabled = $false } 
    Update-MgPolicyIdentitySecurityDefaultEnforcementPolicy -BodyParameter $params
    

    To Enable

    $params = @{ IsEnabled = $true } 
    Update-MgPolicyIdentitySecurityDefaultEnforcementPolicy -BodyParameter $params
    
    0 comments No comments

Your answer

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