使用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 信息的更多相关文章

  1. Azure Powershell获取Azure虚拟机的操作系统型号及具体版本

    Azure ARM 模式虚拟机: 1.登陆Azure账号 Add-AzureRmAccount -EnvironmentName AzurechinaCloud 2.选择指定订阅 Select-Azu ...

  2. Azure Powershell 获取可用镜像 PublisherName,Offer,Skus,Version

    #登录 $username="{登录名}" #定义一个用户账号的变量,可以输入需要登录的订阅账号名称 $password=ConvertTo-SecureString -Strin ...

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

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

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

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

  5. 利用Powershell获取公司内部机器的资源信息,作为企业兴许资产管理的基本途径!

    今天一个哥们问我是否用Powershell 实现.我好久没有写脚本,脚本的协作和调试还是费了一些时间,兴许调试了下.运作没有问题,大家能够參考以下的脚本来丰富您企业须要做的一些事情,脚本代码例如以下: ...

  6. 【Azure Redis 缓存】使用Python代码获取Azure Redis的监控指标值 (含Powershell脚本方式)

    问题描述 通过Metrics监控页面,我们能得知当前资源(如Redis)的运行情况与各种指标.如果我们需要把指标下载到本地或者生成JSON数据导入到第三方的监控平台呢?Azure是否可以通过Pytho ...

  7. 如何使用 Azure PowerShell 在 Azure Marketplace 中查找 Windows VM 映像

    本主题介绍如何使用 Azure PowerShell 在 Azure Marketplace 中查找 VM 映像. 创建 Windows VM 时使用此信息来指定 Marketplace 映像. 确保 ...

  8. 使用PowerShell 连接Azure

    除了使用门户登入外,还可以使用PowerShell的方式来连接Azure.首先要去下载组件 http://azure.microsoft.com/en-us/downloads/?rnd=1 http ...

  9. PowerShell管理Azure

    PowerShell第一次连接Azure1.下载Azure SDK,安装azure powershell http://azure.microsoft.com/zh-cn/downloads/?rnd ...

随机推荐

  1. python3 + selenium + eclipse 中报错:'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

    解决:提示chrome driver没有放置在正确的路径下,于是下载chrome dirver,然后放置到C:\Python36的目录下,再次运行就OK了!

  2. nodejs的mysql模块学习(二)连接数据库

    nodejs连接mysql的方式有两种 官方建议的第一种是 let mysql = require('mysql'); let connection = mysql.createConnection( ...

  3. JavaScript高级程序设计学习笔记第十四章--表单

    1.在 HTML 中,表单是由<form>元素来表示的,而在 JavaScript 中,表单对应的则是 HTMLFormElement 类型. HTMLFormElement 继承了 HT ...

  4. win764位安装mysql-5.6

    1配置mysql的MYSQL_HOME和PATH 增加环境变量: MYSQL_HOME=D:\mysql-5.6.14-winx64 修改环境变脸: 在path后面增加%MYSQL_HOME%\bin ...

  5. Oracle&nbsp;11g&nbsp;R2安装手册(…

    1.Oracle 11g R2安装手册(图文教程)For Windows 1.下载Oracle 11g R2 for Windows版本,下载地址如下官方网站:http://download.orac ...

  6. Django 框架

    MVC 框架和MTV框架  (了解即可) MVC,全名是Model View Controller,是软件工程中的一种软件架构模式,把软件系统分为三个基本部分:模型(Model).视图(View)和控 ...

  7. Java集合Set、Map、HashSet、HashMap、TreeSet、TreeMap等

    1.Set和Map的关系: Set代表一种集合元素无序.不可重复的集合,Map代表一种由多个key-value对组成的集合. Set的集合继承体系: Map关系集合 Map集合的key特征:所有key ...

  8. Razor的主版页面框架

    类似于2.0版本中的MasterPage主版页面框架,不过mvc3.0推出的RazorView内建的主版页面语法与原本的webFormview的MasterPage相差甚远   1,Razor的页面执 ...

  9. Myeclipse如何使用自带git工具向远程仓库提交代码(转)

    Myeclipse如何使用自带git工具向远程仓库提交代码 第一步:将改动的代码标记 项目右键:team->synchronize workspace 点击确定 项目右键>add to g ...

  10. char和nchar,varchar和nvarchar的区别(转载)

    1)       定义: char:    固定长度,存储ANSI字符,不足的补英文半角空格. nchar:   固定长度,存储Unicode字符,不足的补英文半角空格 varchar:  可变长度, ...