使用PowerShell 获取azure image publisher offer sku 信息
使用azure powershell 获取指定区域的可用镜像 publisher offer sku信息
param (
[parameter(Mandatory = $false)]
$LocationName = "ChinaNorth",
[parameter(Mandatory = $false)]
$ExportTo = [Environment]::GetFolderPath("Desktop") + "\" + $LocationName + "-VMImage-" + $(Get-Date -Format "yyyyMMdd-HHmmss") + ".csv"
)
function Check-AzureRmLocation()
{
param
(
[string]$LocationName = $(throw "Parameter missing: -LocationName LocationName")
)
Write-Host "$(Get-Date) * Checking location $LocationName" -ForegroundColor Cyan
$Location = Get-AzureRmLocation | Where-Object { $_.Location -eq $LocationName }
If (-not ($Location))
{
Write-Host "$(Get-Date) * The location" $LocationName "does not exist." -ForegroundColor Red
return $false
}
Else
{
Write-Host "$(Get-Date) * Location $LocationName exists" -ForegroundColor Cyan
return $true
}
}
$LocationExist = Check-AzureRmLocation -LocationName $LocationName
if ($LocationExist -eq $true)
{
write-host "$(Get-Date) * Begin to collect VM Image information..Please wait" -ForegroundColor 'Cyan'
[pscustomobject[]]$VMImageObjects = $null
if (Test-Path $ExportTo)
{
Clear-Content $ExportTo -Force
}
$Error.clear()
try
{
$Publishers = (Get-AzureRmVMImagePublisher -Location $LocationName -ErrorAction Stop).PublisherName
$TotalPublisherCounts = $Publishers.count
$PublisherCount = 1
foreach ($Publisher in $Publishers)
{
Write-Progress -Activity ("Current Publisher: $Publisher") -Status "Searching $PublisherCount Publisher, Total Publisher: $TotalPublisherCounts" -PercentComplete ($PublisherCount/ $TotalPublisherCounts * 100) -Id 1
$Offers = (Get-AzureRmVMImageOffer -Location $LocationName -PublisherName $Publisher -ErrorAction Stop).offer
$TotalOfferCounts = $Offers.count
if ($TotalOfferCounts -eq 0)
{
$PublisherCount++
}
else
{
$OfferCount = 1
foreach ($Offer in $Offers)
{
Write-Progress -Activity ("Current Offer: $Offer") -Status "Searching $OfferCount Offer, Total Offer: $TotalOfferCounts" -PercentComplete ($OfferCount/ $TotalOfferCounts * 100) -Id 2 -ParentId 1
$Skus = Get-AzureRmVMImageSku -Location $LocationName -PublisherName $Publisher -Offer $Offer -ErrorAction Stop
$TotalSkuCounts = $Skus.count
if ($TotalSkuCounts -eq 0)
{
$OfferCount++
}
else
{
$SkuCount = 1
foreach ($Sku in $Skus)
{
$VMImageObject = New-Object -TypeName psobject
$VMImageObject | Add-Member -MemberType NoteProperty -Name LocationName -Value $Sku.Location
$VMImageObject | Add-Member -MemberType NoteProperty -Name PublisherName -Value $Sku.PublisherName
$VMImageObject | Add-Member -MemberType NoteProperty -Name OfferName -Value $Sku.Offer
$VMImageObject | Add-Member -MemberType NoteProperty -Name SkuName -Value $Sku.skus
$VMImageObjects += $VMImageObject
Write-Progress -Activity ("Current Sku: $($Sku.skus)") -Status "Searching $SkuCount Sku, Total Sku: $TotalSkuCounts" -PercentComplete ($SkuCount/ $TotalSkuCounts * 100) -id 3 -ParentId 2
Start-Sleep -Milliseconds 500
$SkuCount++
}
$OfferCount++
}
}
$PublisherCount++
}
}
if ($VMImageObjects -ne $null)
{
$VMImageObjects | Export-Csv -LiteralPath $ExportTo -NoTypeInformation -Force -ErrorAction Stop
Write-Host "$(Get-Date) * Export successfully, Please check $ExportTo" -ForegroundColor Cyan
}
else
{
Write-Host "$(Get-Date) * Something wrong" -ForegroundColor Red
}
}
catch
{
Write-Warning $Error[0].Exception.Message
}
}
使用PowerShell 获取azure image publisher offer sku 信息的更多相关文章
- Azure Powershell获取Azure虚拟机的操作系统型号及具体版本
Azure ARM 模式虚拟机: 1.登陆Azure账号 Add-AzureRmAccount -EnvironmentName AzurechinaCloud 2.选择指定订阅 Select-Azu ...
- Azure Powershell 获取可用镜像 PublisherName,Offer,Skus,Version
#登录 $username="{登录名}" #定义一个用户账号的变量,可以输入需要登录的订阅账号名称 $password=ConvertTo-SecureString -Strin ...
- Azure Powershell获取指定订阅下的虚拟机信息(ARM)
为方便Azure用户导出已创建虚拟机的相关信息,特编写如下脚本: 详情脚本: # 登陆Azure Account Add-AzureRmAccount -EnvironmentName AzureCh ...
- Azure Powershell获取指定订阅下的虚拟机信息(ASM)
为方便Azure用户导出已创建虚拟机的相关信息,特编写如下脚本: 详情脚本: # 登陆Azure Account Add-AzureAccount -Environment AzureChinaClo ...
- 利用Powershell获取公司内部机器的资源信息,作为企业兴许资产管理的基本途径!
今天一个哥们问我是否用Powershell 实现.我好久没有写脚本,脚本的协作和调试还是费了一些时间,兴许调试了下.运作没有问题,大家能够參考以下的脚本来丰富您企业须要做的一些事情,脚本代码例如以下: ...
- 【Azure Redis 缓存】使用Python代码获取Azure Redis的监控指标值 (含Powershell脚本方式)
问题描述 通过Metrics监控页面,我们能得知当前资源(如Redis)的运行情况与各种指标.如果我们需要把指标下载到本地或者生成JSON数据导入到第三方的监控平台呢?Azure是否可以通过Pytho ...
- 如何使用 Azure PowerShell 在 Azure Marketplace 中查找 Windows VM 映像
本主题介绍如何使用 Azure PowerShell 在 Azure Marketplace 中查找 VM 映像. 创建 Windows VM 时使用此信息来指定 Marketplace 映像. 确保 ...
- 使用PowerShell 连接Azure
除了使用门户登入外,还可以使用PowerShell的方式来连接Azure.首先要去下载组件 http://azure.microsoft.com/en-us/downloads/?rnd=1 http ...
- PowerShell管理Azure
PowerShell第一次连接Azure1.下载Azure SDK,安装azure powershell http://azure.microsoft.com/zh-cn/downloads/?rnd ...
随机推荐
- 《精通Spring4.X企业应用开发实战》读后感第五章(Bean作用域)
- C 汉字处理
好像有个wchar_t类型的,这里不深究了,只研究char型(1个字符大小)的 1.定义 直接使用char,但每个汉字占据2个字符,所以必须以字符串形式存在 char s[10]; 2.定义时直接赋值 ...
- Windows下怎样安装Tomcat
Tomcat 是开源的WEB应用容器,所以受到各位程序员和公司的亲赖.在这里给大家介绍一下如何在Windows环境下安装Tomcat绿色版本,希望能够对大家有帮助. 1.首先去Tomcat官网下载To ...
- htons和htonl函数具体应用
htons和htonl函数具体应用 htons和htonl函数,是用来将主机字节顺序转换为网络字节顺序在进行网络抓包时,抓到的包的数据是网络字节顺序,在进行编程时,要进行主机字节顺序和网络字节顺序间的 ...
- udp通信的消息处理方案
0.引言 大家都知道当使用udp通信时,最大的一个问题是会出现丢包的情况,那么如何可以既使用udp来传输,又同时能有效防止丢包呢? 本文提供一种简单有效的方法,可以显著避免udp丢包的问题.此外,如果 ...
- Ext.apply(src,apply) 和 Ext.applyIf(src,apply)比较(转)
Ext.onReady(function(){ /* * Ext.apply(src,apply) 和 Ext.applyIf(src,apply) 两个方法的使用和区别比较 */ //Ext.app ...
- 3dmax导出缩放
参考 http://blog.dou.li/unity3d-import-3dmax-model-scale.html http://blog.csdn.net/pdw_jsp/article/det ...
- 「GXOI / GZOI2019」逼死强迫症——斐波那契+矩阵快速幂
题目 [题目描述] ITX351 要铺一条 $2 \times N$ 的路,为此他购买了 $N$ 块 $2 \times 1$ 的方砖.可是其中一块砖在运送的过程中从中间裂开了,变成了两块 $1 \t ...
- CentOS6.5安装sqlite3[转]
1.下载安装包:https://www.sqlite.org/download.html 2.解压 [root@mycentos ~]# tar xzvf sqlite-snapshot-201809 ...
- 13.Python略有小成(装饰器,递归函数)
Python(装饰器,递归函数) 一.开放封闭原则 软件面世时,不可能把所有的功能都设计好,再未来的一两年功能会陆续上线,定期更新迭代,软件之前所用的源代码,函数里面的代码以及函数的调用方式一般不 ...