Hi ,
To disable public access for an Azure Monitor workspace, you can use the az monitor workspace update
command in your PowerShell script. Specifically, you can set the --public-network-access-for-logs
parameter to Disabled
. Here's how you can modify your script:
# Azure Monitor workspace creation
try {
# Check if the Azure Monitor workspace already exists
$existingWorkspace = az monitor account show --resource-group $ResourceGroupName --name $MonitorWorkspace --query name --output tsv
if (-not $existingWorkspace) {
# Azure Monitor workspace does not exist, so create it
az monitor account create --name $MonitorWorkspace --resource-group $ResourceGroupName --location $region --tags "$Tagkey=$Tagvalue"
# Disable public access for the created workspace
az monitor workspace update --resource-group $ResourceGroupName --name $MonitorWorkspace --public-network-access-for-logs Disabled
}
else {
# Azure Monitor workspace already exists
Write-Host "Azure Monitor workspace '$MonitorWorkspace' already exists in resource group '$ResourceGroupName'."
}
} catch {
# Handle errors, e.g., output an error message
Write-Host "Error occurred: $_"
}
Doc for ref : https://learn.microsoft.com/en-us/cli/azure/monitor/log-analytics/workspace?view=azure-cli-latest Please accept answer if it helped