码迷,mamicode.com
首页 > 其他好文 > 详细

一次性查看Azure订阅下所有虚拟机VM的公网IP/Public IP和私网IP/Private IP

时间:2015-05-19 16:36:59      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:

一次性查看Azure订阅下所有虚拟机VM的公网IP/Public IP和私网IP/Private IP,PowerShell脚本如下:


$script_path = Split-Path -Parent $MyInvocation.MyCommand.Definition
cd $script_path

Import-Module ‘C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Azure.psd1‘

Set-ExecutionPolicy Unrestricted

Import-AzurePublishSettingsFile ‘my.publishsettings‘

‘Export VM List‘

$sub = Get-AzureSubscription -Current
Set-AzureSubscription -SubscriptionName $sub.SubscriptionName -ServiceEndpoint "https://management.core.chinacloudapi.cn/"

$resultArray = @()
$vms = Get-AzureVM
foreach($vm in $vms)
{
$vmName = $vm.Name
$dnsName = $vm.ServiceName
$persistVM = Get-AzureVM -ServiceName $dnsName -Name $vmName
$vmSubnet = Get-AzureSubnet -VM $persistVM
$azureDeployment = Get-AzureDeployment -ServiceName $dnsName -Slot Production
$vmBRSubnetMask = ‘‘
if($azureDeployment.VNetName -ne $null)
{
$vnetSites = Get-AzureVNetSite -VNetName $azureDeployment.VNetName
foreach($subnet in $vnetSites.Subnets)
{
if($subnet.Name -eq $vmSubnet)
{
$vmBRSubnetMask = $subnet.AddressPrefix
break
}
}
}
$vmBRIp = $persistVM.IpAddress

$vmEndpoints = Get-AzureEndpoint -VM $persistVM
if($vmEndpoints -ne $null)
{
$vmFRIp = $vmEndpoints[0].Vip
}

$vmObject = New-Object PSObject
$vmObject | Add-Member -MemberType NoteProperty -Name "HostName" -Value $vmName
$vmObject | Add-Member -MemberType NoteProperty -Name "DnsName" -Value $dnsName‘.chinacloudapp.cn‘
$vmObject | Add-Member -MemberType NoteProperty -Name "FR IPv4 Address" -Value $vmFRIp
$vmObject | Add-Member -MemberType NoteProperty -Name "BR IPv4 Address" -Value $vmBRIp
$vmObject | Add-Member -MemberType NoteProperty -Name "BR Subnet Mask" -Value $vmBRSubnetMask
$vmObject | Add-Member -MemberType NoteProperty -Name "DHCP" -Value ‘Yes‘

$resultArray += $vmObject
}

$resultArray | Export-Csv vmlist.csv -NoTypeInformation

‘Done‘
Pause

??

一次性查看Azure订阅下所有虚拟机VM的公网IP/Public IP和私网IP/Private IP

标签:

原文地址:http://blog.csdn.net/dennymvp/article/details/45845287

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!