Home › Studies › SC-500 › CLI & PowerShell Commands

CLI & PowerShell Commands

SC-500 tasks with the Azure CLI and PowerShell side by side for each domain, copied from the topic pages.

Every command here comes from a CLI or PowerShell table on one of the SC-500 topic pages. A - means the topic page gives no command for that tool. Placeholders such as <rg> are yours to fill in.

Manage identity, access, and governance (20–25%)

Entra ID Access & App Identity

TaskAzure CLIPowerShell
Remove role assignments whose identity was deleted (ObjectType Unknown)-Get-AzRoleAssignment | Where-Object {$_.ObjectType -eq "Unknown"} | Remove-AzRoleAssignment
Connect to Graph to change user consent settings-Connect-MgGraph -Scopes "Policy.ReadWrite.Authorization"
Update the default user consent policies-Update-MgPolicyAuthorizationPolicy -BodyParameter $body

Azure Key Vault

TaskAzure CLIPowerShell
Create a vault with Azure RBAC and purge protectionaz keyvault create --name "<vault-name>" --resource-group "myResourceGroup" --enable-rbac-authorization true --enable-purge-protection true-
Assign a Key Vault data plane roleaz role assignment create --role "Key Vault Secrets Officer" --assignee <user-principal-name> --scope /subscriptions/<subscription-id>/resourcegroups/<resource-group>/providers/Microsoft.KeyVault/vaults/<vault-name>New-AzRoleAssignment -RoleDefinitionName "Key Vault Secrets Officer" -SignInName <user-principal-name> -Scope "/subscriptions/<subscription-id>/resourcegroups/<resource-group>/providers/Microsoft.KeyVault/vaults/<vault-name>"
Let trusted Microsoft services bypass the firewallaz keyvault update --resource-group "myresourcegroup" --name "mykeyvault" --bypass AzureServicesUpdate-AzKeyVaultNetworkRuleSet -VaultName "mykeyvault" -Bypass AzureServices
Add an IP address ruleaz keyvault network-rule add --resource-group "myresourcegroup" --name "mykeyvault" --ip-address "191.10.18.0/24"Add-AzKeyVaultNetworkRule -VaultName "mykeyvault" -IpAddressRange "16.17.18.0/24"
Enable the Key Vault service endpoint on a subnetaz network vnet subnet update --resource-group "myresourcegroup" --vnet-name "myvnet" --name "mysubnet" --service-endpoints "Microsoft.KeyVault"-
Set the firewall default action to denyaz keyvault update --resource-group "myresourcegroup" --name "mykeyvault" --default-action DenyUpdate-AzKeyVaultNetworkRuleSet -VaultName "mykeyvault" -DefaultAction Deny
Disable public network accessaz keyvault update --resource-group "myresourcegroup" --name "mykeyvault" --public-network-access DisabledUpdate-AzKeyVault -ResourceGroupName "myresourcegroup" -VaultName "mykeyvault" -PublicNetworkAccess "Disabled"
Set a key rotation policyaz keyvault key rotation-policy update --vault-name <vault-name> --name <key-name> --value </path/to/policy.json>Set-AzKeyVaultKeyRotationPolicy -VaultName <vault-name> -KeyName <key-name> -ExpiresIn (New-TimeSpan -Days 720) -KeyRotationLifetimeAction @{Action="Rotate";TimeAfterCreate= (New-TimeSpan -Days 540)}
Rotate a key nowaz keyvault key rotate --vault-name <vault-name> --name <key-name>Invoke-AzKeyVaultKeyRotation -VaultName <vault-name> -Name <key-name>

Azure Policy & Compliance

TaskAzure CLIPowerShell
Create a delete lock on a resource groupaz lock create --name LockGroup --lock-type CanNotDelete --resource-group exampleresourcegroupNew-AzResourceLock -LockName LockGroup -LockLevel CanNotDelete -ResourceGroupName exampleresourcegroup
Create a policy remediation taskaz policy remediation create --name myRemediation --policy-assignment '/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyAssignments/{myAssignmentId}'-
Get the role ID for roleDefinitionIdsaz role definition list --name "Contributor"-
Preview a Bicep deploymentaz deployment group what-if-
Let a key vault serve template deploymentsaz keyvault update --name ExampleVault --enabled-for-template-deployment trueSet-AzKeyVaultAccessPolicy -VaultName ExampleVault -EnabledForTemplateDeployment

RBAC & Backup Security

TaskAzure CLIPowerShell
Assign an Azure roleaz role assignment create --assignee "{assignee}" --role "{roleNameOrId}" --scope "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}"New-AzRoleAssignment -SignInName <emailOrUserprincipalname> -RoleDefinitionName <roleName> -ResourceGroupName <resourceGroupName>
Create or update an Azure custom role from JSONaz role definition create --role-definition {roleDefinition}-
Create a Resource Guard for MUAaz dataprotection resource-guard create --location "Location" --tags key1="val1" --resource-group "RgName" --resource-guard-name "ResourceGuardName"New-AzDataProtectionResourceGuard -Location “Location” -Name “ResourceGuardName” -ResourceGroupName “rgName”

Topic pages: Entra ID Access & App Identity, Azure Key Vault, Azure Policy & Compliance, RBAC & Backup Security.

Secure storage, databases, and networking (25–30%)

Storage Security

TaskAzure CLIPowerShell
Require secure transferaz storage account update -g {ResourceGroupName} -n {StorageAccountName} --https-only trueSet-AzStorageAccount -Name "{StorageAccountName}" -ResourceGroupName "{ResourceGroupName}" -EnableHttpsTrafficOnly $True
Default network action Denyaz storage account update --resource-group "myresourcegroup" --name "mystorageaccount" --default-action DenyUpdate-AzStorageAccountNetworkRuleSet -ResourceGroupName "myresourcegroup" -Name "mystorageaccount" -DefaultAction Deny
Block all public network accessaz storage account update --name MyStorageAccount --resource-group MyResourceGroup --public-network-access DisabledSet-AzStorageAccount -ResourceGroupName "myresourcegroup" -Name "mystorageaccount" -PublicNetworkAccess Disabled
Enable service endpoint on a subnetaz network vnet subnet update --resource-group "myresourcegroup" --vnet-name "myvnet" --name "mysubnet" --service-endpoints "Microsoft.Storage.Global"-
Add a virtual network ruleaz storage account network-rule add --resource-group "myresourcegroup" --account-name "mystorageaccount" --subnet $subnetidAdd-AzStorageAccountNetworkRule -ResourceGroupName "myresourcegroup" -Name "mystorageaccount" -VirtualNetworkResourceId $subnet.Id
Add an IP network ruleaz storage account network-rule add --resource-group "myresourcegroup" --account-name "mystorageaccount" --ip-address "16.17.18.0/24"Add-AzStorageAccountNetworkRule -ResourceGroupName "myresourcegroup" -AccountName "mystorageaccount" -IPAddressOrRange "16.17.18.0/24"
Set trusted service exceptionsaz storage account update --resource-group "myresourcegroup" --name "mystorageaccount" --bypass Logging Metrics AzureServicesUpdate-AzStorageAccountNetworkRuleSet -ResourceGroupName "myresourcegroup" -Name "mystorageaccount" -Bypass AzureServices,Metrics,Logging
Disallow Shared Key authorizationaz storage account update --name <storage-account> --resource-group <resource-group> --allow-shared-key-access falseSet-AzStorageAccount -ResourceGroupName <resource-group> -AccountName <storage-account> -AllowSharedKeyAccess $false
Disallow anonymous blob access (on create)az storage account create --name <storage-account> --resource-group <resource-group> --kind StorageV2 --location <location> --allow-blob-public-access falseNew-AzStorageAccount -ResourceGroupName $rgName -Name $accountName -Location $location -SkuName Standard_GRS -AllowBlobPublicAccess $false
List account access keysaz storage account keys list --resource-group <resource-group> --account-name <storage-account>(Get-AzStorageAccountKey -ResourceGroupName <resource-group> -Name <storage-account>).Value[0]

Database Security

TaskAzure CLIPowerShell
Create a server-level firewall ruleaz sql server firewall-rule create --resource-group myResourceGroup --server $servername -n ContosoIPRange --start-ip-address 192.168.1.0 --end-ip-address 192.168.1.255New-AzSqlServerFirewallRule -ResourceGroupName "myResourceGroup" -ServerName $servername -FirewallRuleName "ContosoIPRange" -StartIpAddress "192.168.1.0" -EndIpAddress "192.168.1.255"
Create a server-level firewall rule (T-SQL)-EXECUTE sp_set_firewall_rule @name = N'ContosoFirewallRule', @start_ip_address = '192.168.1.1', @end_ip_address = '192.168.1.10'
Enable SQL Database auditing with managed identityaz SQL server audit-policy update -g "sampleresourcegroup" -n "sampleauditingtestserver" --state Enabled --bsts Enabled --storage-endpoint https://<storageaccountname>.blob.core.windows.net --storage-key '""'Set-AzSqlServerAudit -ResourceGroupName "sampleresourcegroup" -ServerName "sampleauditingtestserver" -BlobStorageTargetState Enabled -StorageAccountResourceId "/subscriptions/<SubscriptionID>/resourcegroups/sampleresourcegroup/providers/Microsoft.Storage/storageAccounts/auditingteststorageacc" -UseIdentity True

Private Access & Azure Firewall

TaskAzure CLIPowerShell
Set custom DNS servers on Azure Firewall (PowerShell: set the DNSServer property of the object from Get-AzFirewall, then pipe it to Set-AzFirewall) (needs the azure-firewall CLI extension: az extension add --name azure-firewall)az network firewall update --name fwName --resource-group fwRG --dns-servers 10.1.0.4 10.1.0.5$azFw.DNSServer = $dnsServers
Enable network policies for private endpoints on a subnet (PowerShell: splatted parameters include PrivateEndpointNetworkPoliciesFlag = 'Enabled'; then $vnet | Set-AzVirtualNetwork)az network vnet subnet update --disable-private-endpoint-network-policies false --name default --resource-group myResourceGroup --vnet-name myVNetSet-AzVirtualNetworkSubnetConfig @sub
Find GroupId and MemberName of a private-link resourceaz network private-link-resource list --resource-group MyResourceGroup --name myWebApp1979 --type Microsoft.Web/sitesGet-AzPrivateLinkResource -PrivateLinkResourceId $webapp.ID
Set Azure Firewall SNAT private ranges (classic rules only; PowerShell: on an object from Get-AzFirewall, then Set-AzFirewall -AzureFirewall $azfw)-$azfw.PrivateRange = @("IANAPrivateRanges", "192.168.1.0/24", "192.168.1.10")

Topic pages: Storage Security, Database Security, Private Access & Azure Firewall.

Secure compute (20–25%)

AI Data Risk & Agent ID

TaskAzure CLIPowerShell
Restrict a SharePoint site from Copilot and org-wide search (RCD on)-Set-SPOSite -Identity <site-url> -RestrictContentOrgWideSearch $true
Remove Restricted Content Discovery from a site-Set-SPOSite -Identity <site-url> -RestrictContentOrgWideSearch $false
Create the Entra app for Copilot Studio external threat detection (script option)-.\Create-CopilotWebhookApp.ps1 -TenantId "11111111-2222-3333-4444-555555555555" -Endpoint "https://provider.example.com/threat_detection/copilot" -DisplayName "Copilot Security Integration - Production" -FICName "ProductionFIC"

AI Workload Security

TaskAzure CLIPowerShell
Install the Az PowerShell modules (troubleshooting Purview data security for AI interactions)-Install-Module -Name Az -AllowClobber
Connect to Azure PowerShell as a tenant admin-Connect-AzAccount -Tenant $yourTenantIdHere
Check that the Microsoft Purview service principal exists in the tenant-Get-AzADServicePrincipal -ApplicationId "9ec59623-ce40-4dc8-a635-ed0275b5d58a"
Add the Microsoft Purview service principal to the tenant-New-AzADServicePrincipal -ApplicationId "9ec59623-ce40-4dc8-a635-ed0275b5d58a"

Server & VM Security

TaskAzure CLIPowerShell
Register encryption at host on the subscriptionaz feature register --name EncryptionAtHost --namespace Microsoft.ComputeRegister-AzProviderFeature -FeatureName "EncryptionAtHost" -ProviderNamespace "Microsoft.Compute"
Enable an existing key vault for disk encryptionaz keyvault update --name "<your-unique-keyvault-name>" --resource-group "MyResourceGroup" --enabled-for-disk-encryption "true"Set-AzKeyVaultAccessPolicy -VaultName "<your-unique-keyvault-name>" -ResourceGroupName "MyResourceGroup" -EnabledForDiskEncryption
Enable Azure Disk Encryption with a KEKaz vm encryption enable -g "MyResourceGroup" --name "myVM" --disk-encryption-keyvault "<your-unique-keyvault-name>" --key-encryption-key "myKEK"Set-AzVMDiskEncryptionExtension -ResourceGroupName MyResourceGroup -VMName "MyVM" -DiskEncryptionKeyVaultUrl $KeyVault.VaultUri -DiskEncryptionKeyVaultId $KeyVault.ResourceId -KeyEncryptionKeyVaultId $KeyVault.ResourceId -KeyEncryptionKeyUrl $KEK.Id -SkipVmBackup -VolumeType All
Configure JIT access on a VM-Set-AzJitNetworkAccessPolicy -Kind "Basic" -Location "LOCATION" -Name "default" -ResourceGroupName "RESOURCEGROUP" -VirtualMachine $JitPolicyArr
Request JIT access-Start-AzJitNetworkAccessPolicy -ResourceId "/subscriptions/SUBSCRIPTIONID/resourceGroups/RESOURCEGROUP/providers/Microsoft.Security/locations/LOCATION/jitNetworkAccessPolicies/default" -VirtualMachine $JitPolicyArr
Limit what the Arc agent can do (extension allowlist)azcmagent config set extensions.allowlist "Microsoft.Azure.Monitor/AzureMonitorWindowsAgent,Microsoft.Azure.AzureDefenderForServers/MDE.Windows"-
Disable Arc agent incoming connections and machine configurationazcmagent config set incomingconnections.enabled false azcmagent config set guestconfiguration.enabled false-
Enable Trusted launch on a deallocated Gen2 VMaz vm update --resource-group myResourceGroup --name myVm --security-type TrustedLaunch --enable-secure-boot true --enable-vtpm trueGet-AzVM -ResourceGroupName myResourceGroup -VMName myVm | Update-AzVM -SecurityType TrustedLaunch -EnableSecureBoot $true -EnableVtpm $true

Container Security

TaskAzure CLIPowerShell
Create an AKS cluster with API server authorized IP rangesaz aks create --resource-group myResourceGroup --name myAKSCluster --vm-set-type VirtualMachineScaleSets --load-balancer-sku standard --api-server-authorized-ip-ranges 73.140.245.0/24 --generate-ssh-keysNew-AzAksCluster -ResourceGroupName myResourceGroup -Name myAKSCluster -NodeVmSetType VirtualMachineScaleSets -LoadBalancerSku Standard -ApiServerAccessAuthorizedIpRange '73.140.245.0/24' -GenerateSshKey
Update authorized IP rangesaz aks update --resource-group myResourceGroup --name myAKSCluster --api-server-authorized-ip-ranges 73.140.245.0/24Set-AzAksCluster -ResourceGroupName myResourceGroup -Name myAKSCluster -ApiServerAccessAuthorizedIpRange '73.140.245.0/24'
Disable authorized IP rangesaz aks update --resource-group myResourceGroup --name myAKSCluster --api-server-authorized-ip-ranges ""Set-AzAksCluster -ResourceGroupName myResourceGroup -Name myAKSCluster -ApiServerAccessAuthorizedIpRange ''
Create a private AKS clusteraz aks create --name <private-cluster-name> --resource-group <private-cluster-resource-group> --load-balancer-sku standard --enable-private-cluster --generate-ssh-keys-
Enable Azure RBAC for Kubernetes on an AKS Standard clusteraz aks update --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME --enable-azure-rbac-
Sign in to a registry as your Entra identityaz acr login --name <acrName>Connect-AzContainerRegistry
Get a registry access token without Dockeraz acr login --name <acrName> --expose-token-
Enable the registry admin useraz acr update -n <acrName> --admin-enabled trueUpdate-AzContainerRegistry -Name <acrName> -ResourceGroupName myResourceGroup -EnableAdminUser
Enable anonymous pullaz acr update --name myregistry --anonymous-pull-enabled-
Deny registry access from all networks by defaultaz acr update --name myContainerRegistry --default-action Deny-
Disable public network access to a registryaz acr update --name myContainerRegistry --public-network-enabled false-
Assign a system-assigned identity to a container appaz containerapp identity assign --name myApp --resource-group myResourceGroup --system-assigned-

App Platform Security

TaskAzure CLIPowerShell
Add an App Service access restriction ruleaz webapp config access-restriction add --resource-group ResourceGroup --name AppName --rule-name 'IP example rule' --action Allow --ip-address 122.133.144.0/24 --priority 100Add-AzWebAppAccessRestrictionRule -ResourceGroupName "ResourceGroup" -WebAppName "AppName" -Name "Multi-source rule" -IpAddress "192.168.1.0/24,192.168.10.0/24,192.168.100.0/24" -Priority 100 -Action Allow
Allow Azure Front Door only (service tag rule)az webapp config access-restriction add --resource-group ResourceGroup --name AppName --rule-name "Azure Front Door example" --action Allow --priority 200 --service-tag AzureFrontDoor.Backend --http-header x-azure-fdid=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-
Assign a system-assigned managed identity to an appaz webapp identity assign --resource-group <group-name> --name <app-name>Set-AzWebApp -AssignIdentity $true -ResourceGroupName <group-name> -Name <app-name>
Route all outbound traffic through the virtual network (Key Vault reference to a restricted vault)az webapp config set --resource-group <group-name> --subscription <subscription> --name <app-name> --generic-configurations '{"vnetRouteAllEnabled": true}'Update-AzFunctionAppSetting -Name <app-name> -ResourceGroupName <group-name> -AppSetting @{vnetRouteAllEnabled = $true}

Topic pages: AI Data Risk & Agent ID, AI Workload Security, Server & VM Security, Container Security, App Platform Security.

Manage and monitor security posture (20–25%)

Microsoft Sentinel

TaskAzure CLIPowerShell
Create a custom table in a Log Analytics workspaceaz monitor log-analytics workspace table create --resource-group "$resourceGroupName" --workspace-name "$workspaceName" --name "$tableName" --plan Analytics --columns TimeGenerated=datetime RawData=stringNew-AzOperationalInsightsTable @newAzOperationalInsightsTableParams
Test an XPath query for a Windows events DCR-Get-WinEvent -LogName 'Application' -FilterXPath $XPath
Check whether audit log search is on (Exchange Online PowerShell)-Get-AdminAuditLogConfig | Format-List UnifiedAuditLogIngestionEnabled
Turn audit log search off (Exchange Online PowerShell)-Set-AdminAuditLogConfig -UnifiedAuditLogIngestionEnabled $false
Search the audit log from PowerShell (Exchange Online PowerShell)-Search-UnifiedAuditLog

Topic pages: Microsoft Sentinel.

Pages with no command table

These topic pages have no CLI or PowerShell table, so nothing from them is repeated here: Network Controls & VPN, Defender for Cloud Posture, Security Copilot.