使用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 ...
随机推荐
- sql 的基础语句
USE day15; -- 创建表CREATE TABLE teacher( id INT, NAME VARCHAR(20))-- 查看所有表SHOW TABLES; DESC student; D ...
- java:Socket介绍(一)
Socket是应用层与TCP/IP协议族通信的中间软件抽象层,它是一组接口.在设计模式中,Socket其实就是一个门面模式,它把复杂的TCP/IP协议族隐藏在Socket接口后面,对用户来说,一组简单 ...
- [xdoj1233]Glory and LCS
题意:求两个排列的最长公共子序列n<=1e5 解题关键:转化为LIS. 最长公共子序列 的 nlogn 的算法本质是 将该问题转化成 最长增序列(LIS),因为 LIS 可以用nlogn实现,所 ...
- R 中数据导入
R语言数据导入 数据导入 1.保存和加载R的数据(与R.data的交互:save()函数和load()函数) a <- 1:10 save(a, file = "data/dumDa ...
- SQL中的drop,truncate和delete的区别
(1) DELETE语句执行删除的过程是每次从表中删除一行,并且同时将该行的删除操作作为事务记录在日志中保存以便进行进行回滚操作.TRUNCATE TABLE 则一次性地从表中删除所有的数据并不把 ...
- Linux/Unix中的命令提示符prompt
用惯了DOS的伙计刚用Unix时最想干的事情就是想把Unix搞得像DOS一些, 其中的一条就是把Unix的提示符设置成$p$g那样的.下面就说一说做的方法. 不同的SHELL设置的方法不同,比较方便的 ...
- 如何升级一个JavaWeb应用
准备db变更 准备整个war包或变更的文件 上传文件至云盘(通常直接上传文件较慢,建议先传到云盘,然后下载) 从云盘下载 执行db变更 解压war到指定目录或替换变更的文件 修改设计IP地址的配置文 ...
- java继承使用的细节问题?
关于java继承的基本概念就不多说了,下面就说说继承使用应该注意的细节问题? 示例 一: package com.bizvane; class Fu{ public Fu() { System.out ...
- SP2-0734: 未知的命令开头 “IMP ” - 忽略了剩余的行
描述 在cmd命令窗口中使用imp命令将dmp文件导入到oracle中时,出现了错误: SP2-0734: 未知的命令开头 “IMP ” - 忽略了剩余的行,如图 原因 imp命令是oracle提供的 ...
- php如何判断文件是否存在,包括本地和远程文件
当检查的文件是本地时用PHP自带的file_exists检查就行了,而此函数只能检查本地的函数是否存在, 所以如果要检查远程的文件是否存在只能用其它的方法了. 如果所服务器中php的配置开启了“all ...