使用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 ...
随机推荐
- Nuget:template
ylbtech-Nuget: 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 6.返回顶部 作者:ylbtech出处:http://ylbtech.c ...
- 【opencv学习笔记二】opencv3.4.0组件结构说明
在学习opencv使用之前我们先来看一下opencv有哪些组件结构.至于OpenCV组件结构的研究方法, 我们不妨管中窥豹,通过opencv安装路径下include目录里面头文件的分类存放,来一窥Op ...
- DataTable批量插入数据库
最近在将excel中的文件导入到数据库中,用程序进行编写,由于数据量较大所以速度很慢,后来采用了SqlBulkCopy类,解决了速度的问题,我就insert语句,sqldataadapter.upda ...
- 错误: 实例 "ahwater-linux-core" 执行所请求操作失败,实例处于错误状态。: 请稍后再试 [错误: Exceeded maximum number of retries. Exceeded max scheduling attempts 3 for instance 7c1609c9-9d0f-4836-85b3-cefd45f942a7. Last exception: [u
错误: 实例 "ahwater-linux-core" 执行所请求操作失败,实例处于错误状态.: 请稍后再试 [错误: Exceeded maximum number of ret ...
- 集成hibernateDaoSupport实现增删改查
1. package edu.jlu.fuliang.dao.impl; import java.util.List; import org.springframework.orm.hibernate ...
- CF-839B
B. Game of the Rows time limit per test 1 second memory limit per test 256 megabytes input standard ...
- sparse matrix format
see Spare Matrix wikipedia item, and scipy's documentation on different choices of sparse matrix typ ...
- 一文带你认识Java8中接口的默认方法
Java8是Oracle于2014年3月发布的一个重要版本,其API在现存的接口上引入了非常多的新方法. 例如,Java8的List接口新增了sort方法.在Java8之前,则每个实现了List接口的 ...
- UE4 Runtime下动态给Actor添加组件
http://www.v5xy.com/?p=858 UE4的组件分为两种:USceneComponent, UActorComponent UActorComponent (NewObject(th ...
- 以太坊开发教程(一) truffle框架简介/安装/使用
通常一个DAPP的开发包括两部分:智能合约的开发和提供合约进行调用的前端页面. truffle提供了对这两部分内容比较简单的开发方式,特别是在开发/测试阶段.给开发人员提供快捷的打包/部署,已经本地服 ...