0

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

# Create a Lab with Windows server

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

#参数 (

     $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."
4

1 回答 1

0

关于这个问题,请将表达式更新为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

在此处输入图像描述

于 2021-04-12T02:39:27.710 回答