簡體   English   中英

需要 Powershell 腳本來獲取所有公共 IP 地址,並在所有訂閱中附加資源名稱、資源組

[英]Need Powershell script to get all public IP addresses with attached resource name, Resource group, in all subcriptions

在我們的組織中,大約有 4,000 個訂閱。 所以我需要一個 powershell 腳本來獲取所有帶有附加資源名稱的公共 IP 地址,格式為 excel 或 csv。

使用下面的腳本,但它只顯示 IP 地址:

az login

$Subscriptions = Get-AzSubscription

foreach ($sub in $Subscriptions) { az network public-ip list --subscription $sub.Name --query "[?ipAddress!=null]|[?contains(ipAddress, '$IP')].[ipAddress]" --output table }

獲取所有訂閱中所有帶有附加資源名稱、資源組的公共 IP 地址:

使用 azure PowerShell 命令Get-AZPublicIpAddress

 Get-AzPublicIpAddress | Export-Csv -Path /home/pathxxxx/new.csv | format-table

獲取資源組、資源以及創建數據等字段,如圖所示:

在此處輸入圖像描述

如果需要特定訂閱,請使用以下腳本設置訂閱:

$subsscriptions = Get-AzSubscription 
foreach ($subscription in $subscriptions) {
    Write-Host "$subscription.Name"
$SelectSub = Select-AzSubscription -SubscriptionName $subscription.Name
}
#Add code here as per the requirement#

使用export-CSV powershell 命令將 output 導出到 excel 工作表在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM