使用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. 分布式环境下的session管理

    一.分布式Session的几种实现方式 1.1.基于cookie 进行session共享 简单.方便,每次通过判断cookie中的用户状态信息判断用户的登录状态:但是用户信息要存在客户端,存在安全隐患 ...

  2. 网络编程 recv()函数

    recv()是编程语言函数. 函数原型int recv( _In_ SOCKET s, _Out_ char *buf, _In_ int len, _In_ int flags); 这里只描述同步S ...

  3. C# DataGridView的單元格中只能輸入數字

    控件類型:DataGridView 控件名稱:dgvGift_Condition 裏面用到的:IsNumeric.NotePastText.RestoreText 等請參見 前一日志“TextBox中 ...

  4. Swing 添加Esc快捷键退出程序

    JFrame demo = new JFrame(); demo.addKeyListener( new KeyListener(){ public void keyReleased(KeyEvent ...

  5. <正则吃饺子>:关于java中对内存部分的简单总结整理

    在项目和一些群讨论中,经常看到对内存的处理,但是,自己确是一知半解的,基于此,就把这部分的知识简单的整理了下,知识点来源于网络博文,也一一标明出处,谢谢. package com.love.malin ...

  6. mysql由浅入深探究(二)----mysql用户操作

    上一节我们完成了mysql的安装,现在我们将开启实战模式,完成一些基本的mysql操作.这节我们分为一些几个内容: mysql中用户新建 mysql中用户删除 mysql中用户修改 mysql中用户查 ...

  7. Fedora/CentOS使用技巧

    命令 获取系统安装包的编译源码及脚本 # dnf download --source package # yumdownloader --source virt-viewer 远程连接windows ...

  8. solidity 学习笔记(3) 函数修饰符/继承

    修饰符: 函数修饰符有 constant  view pure 其中 constant和view的功能是一样的  不会消耗gas 也就是说不会做任何存储   constant在5.0以后的版本中被废弃 ...

  9. codevs1251 括号

    1251 括号  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold       题目描述 Description 计算乘法时,我们可以添加括号,来改变相乘的顺序,比 ...

  10. [Xcode 实际操作]六、媒体与动画-(17)使用MediaPlayer框架播放视频

    目录:[Swift]Xcode实际操作 本文将演示视频的播放功能. 在项目名称上点击鼠标右键,弹出右键菜单, 选择[Add Files to "DemoApp"],往项目中导入文件 ...