question

Etudiantvm03-9670 avatar image
0 Votes"
Etudiantvm03-9670 asked Etudiantvm03-9670 commented

deploy Lab with windows image

Hi,
I try to create a lab Windows 10 or Windows Server in a lab account with PowerShell but he doesn't found any image except when I put :
Image = 'Centos-Based
' he create a lab with centos-based 8.1
my code please :

 # Create a Lab with Windows server
    
 $la  = Get-AzLabAccount -ResourceGroupName $ResourceGroupName -LabAccountName $LabAccountName
 Write-Host "$LabAccountName lab account created or found."
    
  #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."




azure-labservicesazure-lab-services-templates-virtual-machinesazure-lab-services-automationazure-lab-services-base-images
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

any help please ?

0 Votes 0 ·

any one help me?

0 Votes 0 ·

@Etudiantvm03-9670 , thank you for reaching out to us. Happy to help. I cannot reproduce the issue as the above script is incomplete (you are looping through $LabAccount but it is not assigned any value). Can you pls check out and implement just like this sample script published by PG and see if it helps?

Pls try out the above script and if it does not work, share the complete script to me to help you further. Additionally, let me know for which region you are running this script.

Also, do check out Az.LabServices for more context.



0 Votes 0 ·

@Etudiantvm03-9670 , just checking in to see if you got a chance to check out my previous response.

0 Votes 0 ·

@Etudiantvm03-9670 , just checking in to see if you got a chance to check out my previous response.

0 Votes 0 ·

0 Answers