zoukankan      html  css  js  c++  java
  • 使用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
            
        }
        
        
    }
  • 相关阅读:
    Linux 的伪终端的基本原理 及其在远程登录(SSH,telnet等)中的应用
    入住cnblogs第一篇随笔 Hello, world!
    清除maven加载失败的jar包记录
    解决Jackson2反序列化LocalDateTime报错
    springboot+dubbo基于zookeeper快速搭建一个demo
    解决bug:sprongboot2整合shiro,swagger2页面样式加载不出来问题
    Tomcat 8启动速度慢原因1: At least one JAR was scanned for TLDs yet contained no TLDs
    解决exlicpe以debug模式启动或运行速度非常慢的问题
    MAVEN打包报错:com.sun.net.ssl.internal.ssl;sun.misc.BASE64Decoder;程序包 javax.crypto不存在处理办法
    SQL根据B表内容修改A表内容,查询表中重复记录,删除掉重复项只保留一条
  • 原文地址:https://www.cnblogs.com/oceanwang/p/10205536.html
Copyright © 2011-2022 走看看