使用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 ...
随机推荐
- css3 翻起页脚
html <div class="demo2"> <img src="images/1.jpg"> </div> css . ...
- 用python监控您的window服务
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://world77.blog.51cto.com/414605/782935 最近比较 ...
- Spring Boot错误errMsg: "request:ok"
在把评论写到数据库并且动态刷新评论区的时候,有时候正常写入,有时候就会有“request:ok”的的错误出现,错误信息如下: data: {timestamp: , error: "Inte ...
- IIS 中的虚拟目录 和软连接
在WIndows 中 可以这样设置 mklink /D C:\bb C:\cc 这样 bb 就指向 CC了 bb 在IIS中的目录其实就是虚拟目录 .这样大的文件就不用存放在IIS中了,可以放在其他 ...
- LeetCode: 598 Range Addition II(easy)
题目: Given an m * n matrix M initialized with all 0's and several update operations. Operations are r ...
- React 从入门到进阶之路(五)
之前的文章我们介绍了 React 事件,方法, React定义方法的几种方式 获取数据 改变数据 执行方法传值.接下来我们将介绍 React 表单事件 键盘事件 事件对象以及 React中 的 re ...
- 30个Python物联网小实验5:光线感应灯
30个Python物联网小实验5:光线感应灯 光线传感器 光线变化执行函数 光线状态执行函数 30个Python物联网小实验5:光线感应灯 光线传感器 可以检测周围环境的亮度: 方向性较好,感知特定方 ...
- Codeforces Round #360 (Div. 1)A (二分图&dfs染色)
题目链接:http://codeforces.com/problemset/problem/687/A 题意:给出一个n个点m条边的图,分别将每条边连接的两个点放到两个集合中,输出两个集合中的点,若不 ...
- 《Python数据科学手册》第五章机器学习的笔记
目录 <Python数据科学手册>第五章机器学习的笔记 0. 写在前面 1. 判定系数 2. 朴素贝叶斯 3. 自举重采样方法 4. 白化 5. 机器学习章节总结 <Python数据 ...
- oracle view and MATERIALIZED VIEW
View http://blog.csdn.net/tianlesoftware/article/details/5530618 MATERIALIZED VIEW http://blog.csdn. ...