這邊蒐集一些常用的到的腳本Scripts
取得Vnet subnet與IP清單
先安裝Module,> Install-Module -Name Az.network
Get-AzSubscription | Foreach-Object { $sub = Set-AzContext -SubscriptionId $_.SubscriptionId $vnets = Get-AzVirtualNetwork foreach ($vnet in $vnets) { [PSCustomObject]@{ Subscription = $sub.Subscription.Name Name = $vnet.Name Vnet = $vnet.AddressSpace.AddressPrefixes -join ', ' Subnets = $vnet.Subnets.AddressPrefix -join ', ' } } } | Export-Csv -Delimiter ";" -Path "AzureVnet.csv"
來源:https://dev.to/roberthstrand/list-all-vnet-and-subnets-across-multiple-subscriptions-4028
列出期間花費
#Install Az.Reservations Module if not exists. #Install-Module -Name Az.Reservations -Scope CurrentUser #Start and End date to fetch consumption usage details of Azure Reservations $startDate = '2021-12-01' $endDate = '2021-12-31' #List all Azure subscriptions $subscriptionIds = Get-AzSubscription foreach ($subscription in $subscriptionIds) { #Change the Subscription Set-AzContext -Subscription $subscription #Get the information of Azure Reservation consumption usage details $info = Get-AzConsumptionUsageDetail -StartDate $startDate -EndDate $endDate #Save the information to Microsoft Excel CSV files with subscription id in the name of file $info | Export-Csv -NoTypeInformation -Path "C:\temp\$($subscription.name).csv" }
其他Cost相關
FAQ:
1. 如果出現Operation returned an invalid status code 'Unauthorized'怎麼辦
A: 輸入> Connect-AzAccount,重新登入帳號解決
沒有留言:
張貼留言