使用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. 水题 等差数列HDU 5400 Arithmetic Sequence

    主要是要知道它对于等差数列的定义,单个数也可以作为等差数列且一定满足题意,另外就是要算清楚区间与区间的关系,考虑两大类情况,一种是d1区间和d2区间连在一起,另外一种情况就是其余情况. #includ ...

  2. 你所不知道的html5与html中的那些事(五)——web图像

    文章简介:       现在的页面,一般都离不开图像,而怎么做才能让我们的页面中的图像加载的又快又好呢?在优化页面速度的时候还有什么事是你所不知道的呢?     下面看看今天我为大家带来了哪些关于we ...

  3. my emacs configuration

    modified from https://github.com/flyingmachine/emacs-for-clojure ;;;; ;; Packages ;;;; ;; Define pac ...

  4. 选择Netty的理由

    摘自:http://blog.csdn.net/u010154380/article/details/64443762 <Netty 权威指南>—— 选择Netty的理由 声明:本文是&l ...

  5. 微信小程序开发之tab导航栏

    实现功能: 点击不同的tab导航,筛选数据 UI:   js: data:{ navbar: ['半月维保', '季度维保', '半年维保',"年度维保"],    //count ...

  6. Working Experience - NLog 多实例时配置文件冲突

    正文 问题: 当前项目已使用 NLog 的情况下再引用使用 NLog 的项目, 出现配置文件冲突, 有一个配置文件不工作 方法: 使用 LogFactory 代替 LogManager 来获取 Log ...

  7. OpenStack日志分析

    日志文件说明 Nova日志 OpenStack计算服务日志位于/var/log/nova目录下(此目录在Controller和Compute节点都存在),默认权限拥有者是nova用户 文件名 作用 n ...

  8. -cogs1247. [Nescafé29] 穿越七色虹

    1247. [Nescafé29] 穿越七色虹 ★   输入文件:rainbow.in   输出文件:rainbow.out   简单对比时间限制:5 s   内存限制:128 MB [背景] 在Ne ...

  9. Linux常用命令(补充)-grep

    grep(global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用正 ...

  10. 用Java创建JMeter变量 - 终极指南

    了解如何在Java中创建不同类型的JMeter变量,不同变量类型的详细信息以及如何避免错误. 在Apache JMeter™中编写负载或功能测试涉及使用不同类型的变量.变量有多种用途,例如,在以下情况 ...