为方便Azure用户导出已创建虚拟机的相关信息,特编写如下脚本:

详情脚本:

# 登陆Azure Account
Add-AzureAccount -Environment AzureChinaCloud # 设置订阅ID
$sub = "******"
Select-AzureSubscription -SubscriptionName $sub # 设置Excel格式
$excel = New-Object -ComObject Excel.Application
$workbook = $excel.Workbooks.add()
$sheet = $workbook.worksheets.Item(1)
$sheet.cells.item(1,1) = "Test"
$excel.Visible = $true for($b = 1 ; $b -le 13 ; $b++)
{
$sheet.cells.item(1,$b).font.bold = $true
#$sheet.cells.item(1,$b).borders.LineStyle = $lineStyle::xlDashDot
$sheet.cells.item(1,$b).borders.ColorIndex = $colorIndex::xlColorIndexAutomatic
$sheet.cells.item(1,$b).borders.weight = $borderWeight::xlMedium
} $x = 2
$lineStyle = "microsoft.office.interop.excel.xlLineStyle" -as [type]
$colorIndex = "microsoft.office.interop.excel.xlColorIndex" -as [type]
$borderWeight = "microsoft.office.interop.excel.xlBorderWeight" -as [type]
$chartType = "microsoft.office.interop.excel.xlChartType" -as [type]
$sheet.cells.item(1,1) = "名称"
$sheet.cells.item(1,2) = "类型"
$sheet.cells.item(1,3) = "状态"
$sheet.cells.item(1,4) = "云服务"
$sheet.cells.item(1,5) = "位置"
$sheet.cells.item(1,6) = "订阅ID"
$sheet.cells.item(1,7) = "内网IP"
$sheet.cells.item(1,8) = "配置信息"
$sheet.cells.item(1,9) = "系统"
$sheet.cells.item(1,10) = "DNS域名"
$sheet.cells.item(1,11) = "公网IP"
$sheet.cells.item(1,12) = "公共端口"
$sheet.cells.item(1,13) = "私有端口" # 定义变量
$vms = Get-AzureVM
$vmCount = $vms.Count # 提取变量Value
for($i=0; $i -lt $vmCount; $i++)
{
$vm = $vms[$i];
$sheet.cells.item($x,1) = $vm.name
$sheet.cells.item($x,2) = "虚拟机(经典)"
$sheet.cells.item($x,3) = $vm.status
$sheet.cells.item($x,4) = $vm.ServiceName
$uri=$vm.VM.OSVirtualHardDisk.MediaLink.AbsoluteUri
$location=Get-AzureDisk | Where-Object {$_.MediaLink -eq $uri}| Select-Object Location
$sheet.cells.item($x,5) = $location.Location
$sheet.cells.item($x,6) = $sub
$sheet.cells.item($x,7) = $vm.IpAddress
$sheet.cells.item($x,8) = $vm.InstanceSize
$sheet.cells.item($x,9) = $vm.VM.OSVirtualHardDisk.OS
$sheet.cells.item($x,10) = $vm.ServiceName+".chinacloudapp.cn"
$endpoints = Get-AzureEndpoint -VM $vm
$endpointsCount = $endpoints.Count
for($j=0; $j -lt $endpointsCount; $j++)
{
$endpoint = $endpoints[$j];
$sheet.cells.item($x,11) = $endpoint.vip
$sheet.cells.item($x,12) = $endpoint.port
$sheet.cells.item($x,13) = $endpoint.localport $x++
}
}
$range = $sheet.usedRange
$range.EntireColumn.AutoFit() | out-null $uri=$vm.VM.OSVirtualHardDisk.MediaLink.AbsoluteUri
$location=Get-AzureDisk | Where-Object {$_.MediaLink -eq $uri}| Select-Object Location

输出项及格式见下:

备注:

1.运行脚本期间可能会出现如下报错,忽略即可,不影响最终的结果统计。

2.该脚本运行前,需要事先定义好订阅

3.该脚本输出的为一个Excel表格,输出期间不要关闭正在运行的Excel

4.如果需要对指定Azure账号下的所有订阅进行统计,可参考如下脚本的遍历订阅方法,参考链接:

https://blogs.msdn.microsoft.com/tomholl/2016/11/22/dumping-details-of-azure-virtual-machines-to-csvexcel/

param(
[string]$file="Azure-Classic-VMs.csv"
) add-azureaccount -Environment AzureChinaCloud $subs = Get-AzureSubscription
$vmobjs = @() foreach ($sub in $subs)
{
Write-Host Processing subscription $sub.SubscriptionName try
{
Select-AzureSubscription -SubscriptionId $sub.SubscriptionId -ErrorAction Continue $vms = Get-AzureVm
$svcs = Get-AzureService foreach ($vm in $vms)
{
$service = $svcs | where-object { $_.ServiceName -eq $vm.ServiceName } $vmInfo = [pscustomobject]@{
'Subscription'=$sub.SubscriptionName
'Mode'='Classic'
'Name'=$vm.Name
'ServiceName' = $vm.ServiceName
'Location' = $service.Location
'VMSize' = $vm.InstanceSize
'Status' = $vm.Status
'AvailabilitySet' = $vm.AvailabilitySetName} $vmobjs += $vmInfo }
}
catch
{
Write-Host $error[0]
}
}

Azure Powershell获取指定订阅下的虚拟机信息(ASM)的更多相关文章

  1. Azure Powershell获取指定订阅下的虚拟机信息(ARM)

    为方便Azure用户导出已创建虚拟机的相关信息,特编写如下脚本: 详情脚本: # 登陆Azure Account Add-AzureRmAccount -EnvironmentName AzureCh ...

  2. [转]C# 获取指定目录下所有文件信息、移动目录、拷贝目录

    原文:http://blog.csdn.net/vchao13/article/details/6200255 1.获取指定目录下所有文件信息 /// <summary> /// 返回指定 ...

  3. C# 获取指定目录下所有文件信息

    /// <summary> /// 返回指定目录下所有文件信息 /// </summary> /// <param name="strDirectory&quo ...

  4. 获取指定订阅下所有Azure ARM虚拟机配置(CPU核数,内存大小,磁盘信息)的使用情况

    脚本内容: <# .SYNOPSIS This script grab all ARM VM VHD file in the subscription and caculate VHD size ...

  5. C# 获取指定目录下所有文件信息、移动目录、拷贝目录

    /// <summary> /// 返回指定目录下的所有文件信息 /// </summary> /// <param name="strDirectory&qu ...

  6. c# 获取指定目录下的所有文件并显示在网页上

    参考文献: FileInfo 的使用  https://msdn.microsoft.com/zh-cn/library/system.io.fileinfo_methods(v=vs.110).as ...

  7. 一个获取指定目录下一定格式的文件名称和文件修改时间并保存为文件的python脚本

    摘自:http://blog.csdn.net/forandever/article/details/5711319 一个获取指定目录下一定格式的文件名称和文件修改时间并保存为文件的python脚本 ...

  8. PHP 获取指定目录下所有文件(包含子目录)

    PHP 获取指定目录下所有文件(包含子目录) //glob — 寻找与模式匹配的文件路径 $filter_dir = array('CVS', 'templates_c', 'log', 'img', ...

  9. TDirectory.GetFileSystemEntries获取指定目录下的目录和文件

    使用函数: System.IOUtils.TDirectory.GetFileSystemEntries 所有重载: class function GetFileSystemEntries(const ...

随机推荐

  1. [已解决]This dependency was not found: * common/stylus/index.styl in ./src/main.js To install it, you can run: npm install --save common/stylus/index.styl

    出现 This dependency was not found: * common/stylus/index.styl in ./src/main.js To install it, you can ...

  2. 关于Bitcoin的分叉之路

    今年对与bitcoin来讲是不平凡的一年,它经历了价格的暴涨.腰斩和再次暴涨,对于这些现象背后的利益博弈网上分析的文章很多,我就不再赘述了.我们从技术的角度上分析一下bitcoin的发展历程,同时预测 ...

  3. RLP

    ** 原创勿转 ** 这是在看devp2p时看到的,英文原文地址:https://github.com/ethereum/wiki/wiki/RLP RLP:  Recursive Length Pr ...

  4. (译)Web是如何工作的(3):HTTP&REST

    原文地址:https://medium.freecodecamp.org/how-the-web-works-part-iii-http-rest-e61bc50fa0a   我们在第一篇文章中介绍了 ...

  5. 8、ABPZero系列教程之拼多多卖家工具 添加手机注册登录功能

    现在网站基本都用手机注册,很少用邮箱注册,本篇内容比较多,代码我会尽量加备注,有些操作需要连续添加几个文件才不报错,如果VS显示错误,请继续后续步骤. 前面已经有一篇文章讲到集成短信发送模块:http ...

  6. 基于Flask实现博客开发--准备工作

    背景说明 本项目是基于<深入理解flask>一书,主要是用来记录学习历程和交流心得,所以写得不好请大神勿喷. 准备工作 virtualenv介绍 也许 Virtualenv 是你在开发中最 ...

  7. 七牛php-sdk使用-文档处理

    所用到的七牛文档转换服务,主要是:ppt文件转为pdf文件,pdf文件转图片(png). 描述一下需求:上传PPT或者PDF文件到七牛,最终转换为图片.文件上传部分的功能已经讲过了,这里说一下转换处理 ...

  8. 爬取网页内容java

    下面介绍的这个方法只是作为抛砖引玉:根据网页URL就可以抓取其中的内容 /** * @title getHtmlResourceByUrl * @param url 网址 * @param encod ...

  9. 分享一个android静默安装,安装后重新启动app的方法

    一:需求简介 之前boss提出一个需求,运行在广告机上的app,需要完成自动升级的功能,广告机是非触摸屏的,不能通过手动点击,所以app必须做到自动下载,自动安装升级,并且安装完成后,app还要继续运 ...

  10. html笔记4

    <html> <body> <p>这是列表标签</p> <ul> <li>xxx</li> </ul> ...