简体   繁体   English

需要 Powershell 脚本来获取所有公共 IP 地址,并在所有订阅中附加资源名称、资源组

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

In our organization, there are about 4,000 subscriptions.在我们的组织中,大约有 4,000 个订阅。 So I need a powershell script to get all public IP addresses with attached resource name, in excel or csv format.所以我需要一个 powershell 脚本来获取所有带有附加资源名称的公共 IP 地址,格式为 excel 或 csv。

Used below scripts but its only showing IP address:使用下面的脚本,但它只显示 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 }

Get all public IP addresses with attached resource name, Resource group, in all subscriptions:获取所有订阅中所有带有附加资源名称、资源组的公共 IP 地址:

Use azure PowerShell command Get-AZPublicIpAddress :使用 azure PowerShell 命令Get-AZPublicIpAddress

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

Get resourcegroup, resource as well as creation data etc fields as shown:获取资源组、资源以及创建数据等字段,如图所示:

在此处输入图像描述

Set subscription using below script if needed for a specific subscription:如果需要特定订阅,请使用以下脚本设置订阅:

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

Exported output to excel sheet using export-CSV powershell command:使用export-CSV powershell 命令将 output 导出到 excel 工作表在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM