Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| azure:qnd:azure_powershell [2022/09/13 16:16] – mgupton | azure:qnd:azure_powershell [2022/10/21 21:58] (current) – [Get Resources] mgupton | ||
|---|---|---|---|
| Line 4: | Line 4: | ||
| Authenticate with Azure, list subscriptions for tenants and select a subscription to work with. | Authenticate with Azure, list subscriptions for tenants and select a subscription to work with. | ||
| <code powershell> | <code powershell> | ||
| - | Connect-AzAccount | + | Connect-AzAccount |
| Get-AzSubscription | Get-AzSubscription | ||
| Line 12: | Line 12: | ||
| ====== Command Context ====== | ====== Command Context ====== | ||
| + | Get Azure tenants that there is an authenticated session for. | ||
| + | < | ||
| + | Get-AzTenant | select id,name | ||
| + | </ | ||
| + | |||
| ==== See and set current context for Azure Powershell commands ==== | ==== See and set current context for Azure Powershell commands ==== | ||
| This shows subscription and tenant info for current connections. | This shows subscription and tenant info for current connections. | ||
| Line 26: | Line 31: | ||
| </ | </ | ||
| + | ==== Remove item from available context ==== | ||
| + | |||
| + | <code powershell> | ||
| + | (Get-AzContext -ListAvailable).Name | ||
| + | </ | ||
| + | |||
| + | <code powershell> | ||
| + | Remove-Context -Name <context name> | ||
| + | </ | ||
| + | |||
| + | ====== Get Resources ====== | ||
| + | List all resources in the current subscription. | ||
| + | <code powershell> | ||
| + | Get-AzResource | ||
| + | </ | ||
| + | |||
| + | <code powershell> | ||
| + | Get-AzResource | select Name, | ||
| + | </ | ||
| ====== Loop Over All Subscriptions ====== | ====== Loop Over All Subscriptions ====== | ||
| Line 47: | Line 71: | ||
| <code powershell> | <code powershell> | ||
| foreach ($sub in Get-AzSubscription -TenantId " | foreach ($sub in Get-AzSubscription -TenantId " | ||
| - | Set-AzContext -Subscription $sub.id | + | Set-AzContext -Subscription $sub.id |
| # | # | ||
| # Other commands | # Other commands | ||
| Line 53: | Line 77: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | |||
| + | <code powershell> | ||
| + | Set-AzContext -Tenant " | ||
| + | |||
| + | foreach ($sub in Get-AzSubscription) { | ||
| + | Set-AzContext -Subscription $sub.id | Out-Null | ||
| + | # | ||
| + | # Other commands | ||
| + | # | ||
| + | } | ||
| + | </ | ||
| + | |||
| ====== Loop Over Resource Groups ====== | ====== Loop Over Resource Groups ====== | ||
| <code powershell> | <code powershell> | ||
| Line 97: | Line 134: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | ====== List Subnets with no associated NSG ====== | ||
| + | <code powershell> | ||
| + | foreach ($sub in Get-AzSubscription -TenantId " | ||
| + | Set-AzContext -Subscription $sub.id | Out-Null | ||
| + | |||
| + | (Get-AzVirtualNetwork | foreach {$_.Subnets} | where {$_.NetworkSecurityGroup -eq $null}).Name | ||
| + | |||
| + | } | ||
| + | </ | ||
| + | |||
| ====== Enumerating Resources ====== | ====== Enumerating Resources ====== | ||