Update snapshot Property by using Azure Automation account

Hanh Trinh 41 Reputation points
2024-04-23T14:49:55.79+00:00

Hello,

I have a Backup vault that takes snapshot for OS disks and shared disks everyday, during 14 days.

When checking the snapshot file, the network setting is enabled public access from all network. Because there are a lot of snapshot file that I need to change network setting to Disable public and private access, so I can't do it manually.

Look forward for so a solution change network setting by using Automation account, please .

Below is my script in automation account, but it was failed :

$snapshotnames = (Get-AzSnapshot -resourceGroupName 'td.hanh').Name  

az snapshot update -snapshotnames $snapshot --network-access-policy DenyAll

Azure Backup
Azure Backup
An Azure backup service that provides built-in management at scale.
1,140 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,132 questions
{count} votes

1 answer

Sort by: Most helpful
  1. SadiqhAhmed-MSFT 38,891 Reputation points Microsoft Employee
    2024-05-09T09:11:26.37+00:00

    Posting the answer on behalf @Hanh Trinh to benefit others looking for solution to a similar issue.

    Get-AzResource -ResourceGroupName $resourceGroupName -TagName "CreatedBy" -TagValue "AzureBackup" | foreach{
                if($_.ResourceType -match "Microsoft.Compute/snapshots"){
                    $name = $_.Name
                    $snapshotupdateconfig = New-AzSnapshotUpdateConfig -NetworkAccessPolicy DenyAll
                    Update-AzSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $name -SnapshotUpdate $snapshotupdateconfig
    
    

    Hope this helps!


    If the response helped, do "Accept Answer" and up-vote it

    0 comments No comments