使用 Azure Labservices 使用 windows 图像部署实验室

deploy Lab with windows image with azure Labservices

我尝试使用 PowerShell 在实验室帐户中创建实验室 Windows 10 或 Windows 服务器,但他没有找到任何图像,除非我输入: Image = 'Centos-Based ' 他用基于centos的8.1创建了一个实验室 请输入我的代码:

# Create a Lab with Windows server

$la = Get-AzLabAccount -ResourceGroupName $ResourceGroupName -LabAccountName $LabAccountName Write-Host“已创建或找到 $LabAccountName 实验室帐户。”

#param (

     $LabName = Read-Host ' Name of Your lab '
     $Image = Read-Host ' Name of Your lab '
     $Size  = Read-Host ' Size of Your lab '
     $InstallGpuDriverEnabled = $false
     $UserName = Read-Host ' UserName of Your lab '
     $Password = Read-Host ' Password of Your lab '
     $UsageQuotaInHours = 10
     $SharedPasswordEnabled = $false
     $idleGracePeriod = 15
     $idleOsGracePeriod = 0
     $idleNoConnectGracePeriod = 15
     $TemplateVmState = "Enabled"

#)

     $img = $la | Get-AzLabAccountGalleryImage | Where-Object {$_.name -like $Image} | Select-Object -First 1
 if(-not $img -or $img.Count -ne 1) {Write-Error "$Image pattern doesn't match just one image."}
 Write-Host "Image $Image found."
    
   begin {  }
 process {
     try {
      foreach ($la in $LabAccount) {

             $labAccountUri = (ConvertToUri -resource $la)
             $createUri = $labAccountUri + "/createLab"
             $labUri = $labAccountUri + "/labs/" + $LabName
             $environmentSettingUri = $labUri + "/environmentsettings/default"
             $sharedPassword = if ($SharedPasswordEnabled) { "Enabled" } else { "Disabled" }
             $imageType = if ($Image.id -match '/galleryimages/') { 'galleryImageResourceId' } else { 'sharedImageResourceId' }

              InvokeRest -Uri $createUri -Method 'Post' -Body (@{
                     name = $LabName
                     labParameters = @{
                         $imageType = $Image.id
                            
                         password = $Password
                         username = $UserName
                         userQuota = "PT$($UsageQuotaInHours.ToString())H"
                         vmSize = $Size
                         sharedPasswordState = $sharedPassword
                         templateVmState = $TemplateVmState
                         idleShutdownMode = $idleShutdownMode
                         idleGracePeriod = "PT$($idleGracePeriod.ToString())M"
                         enableDisconnectOnIdle = $enableDisconnectOnIdle
                         idleOsGracePeriod = "PT$($idleOsGracePeriod.ToString())M"
                         enableNoConnectShutdown = $enableNoConnectShutdown
                         idleNoConnectGracePeriod = "PT$($idleNoConnectGracePeriod.ToString())M"
                         installGpuDriverEnabled = $gpuDriverState
                            
                     }
                 } | ConvertTo-Json) | Out-Null
             }

             $lab = WaitProvisioning -uri $labUri -delaySec 60 -retryCount 120
             WaitProvisioning -uri $environmentSettingUri -delaySec 60 -retryCount 120 | Out-Null
             return $lab
            
     }

     catch {
         Write-Error -ErrorRecord $_ -EA $callerEA
     }
 }

 end { }


 $lab = $la | New-AzLab -LabName $LabName -Image $img -Size $size -UserName $userName -Password $password  -UsageQuotaInHours $usageQuota | Publish-AzLab
 Write-Host "$LabName lab doesn't exist. Created it."

关于这个问题,请将表达式更新为 Where-Object {$_.name -like "Windows 10*"}

例如

 $la = Get-AzLabAccount -ResourceGroupName $ResourceGroupName -LabAccountName $LabAccountName
 $img = $la | Get-AzLabAccountGalleryImage | Where-Object {$_.name -like "Windows 10*"} | Select-Object -First 1