@@ -127,7 +127,6 @@ while ($runCount -le $NumberOfIterations)
127127 Add-AzureRmEnvironment - Name ($SvcAdminEnvironmentName ) `
128128 - ActiveDirectoryEndpoint ($asEndpoints.ActiveDirectoryEndpoint ) `
129129 - ActiveDirectoryServiceEndpointResourceId ($asEndpoints.ActiveDirectoryServiceEndpointResourceId ) `
130- - ADTenant $AADTenantID `
131130 - ResourceManagerEndpoint ($asEndpoints.ResourceManagerEndpoint ) `
132131 - GalleryEndpoint ($asEndpoints.GalleryEndpoint ) `
133132 - GraphEndpoint ($asEndpoints.GraphEndpoint ) `
@@ -151,21 +150,17 @@ while ($runCount -le $NumberOfIterations)
151150 }
152151 }
153152
154- Invoke-Usecase - Name ' UploadWindows2016ImageToPIR ' - Description " Uploads a windows server 2016 image to the PIR " - UsecaseBlock `
153+ if ( Test-Path - Path $WindowsISOPath )
155154 {
156- if ( -not ( Get-AzureRmVMImage - Location " local " - PublisherName " MicrosoftWindowsServer " - Offer " WindowsServer " - Sku " 2016-DataCenter-Core " - ErrorAction SilentlyContinue))
155+ Invoke-Usecase - Name ' UploadWindows2016ImageToPIR ' - Description " Uploads a windows server 2016 image to the PIR " - UsecaseBlock `
157156 {
158- if (-not (Test-Path - Path $WindowsISOPath ))
159- {
160- throw [System.Exception ] " No ISO path found to create the PIR image."
161- }
162- else
157+ if (-not (Get-AzureRmVMImage - Location $ResourceLocation - PublisherName " MicrosoftWindowsServer" - Offer " WindowsServer" - Sku " 2016-DataCenter-Core" - ErrorAction SilentlyContinue))
163158 {
164159 New-Server2016VMImage - ISOPath $WindowsISOPath - TenantId $AADTenantID - ArmEndpoint $AdminArmEndpoint - Version Core - AzureStackCredentials $ServiceAdminCredentials
165160 }
166161 }
167162 }
168-
163+
169164 if ($TenantAdminCredentials )
170165 {
171166 $subscriptionRGName = " ascansubscrrg" + [Random ]::new().Next(1 , 999 )
@@ -185,7 +180,6 @@ while ($runCount -le $NumberOfIterations)
185180 Add-AzureRmEnvironment - Name ($TntAdminEnvironmentName ) `
186181 - ActiveDirectoryEndpoint ($asEndpoints.ActiveDirectoryEndpoint ) `
187182 - ActiveDirectoryServiceEndpointResourceId ($asEndpoints.ActiveDirectoryServiceEndpointResourceId ) `
188- - ADTenant $AADTenantID `
189183 - ResourceManagerEndpoint ($asEndpoints.ResourceManagerEndpoint ) `
190184 - GalleryEndpoint ($asEndpoints.GalleryEndpoint ) `
191185 - GraphEndpoint ($asEndpoints.GraphEndpoint ) `
@@ -388,18 +382,32 @@ while ($runCount -le $NumberOfIterations)
388382 Invoke-Usecase - Name ' DeployARMTemplate' - Description " Deploy ARM template to setup the virtual machines" - UsecaseBlock `
389383 {
390384 $kvSecretId = (Get-AzureKeyVaultSecret - VaultName $keyVaultName - Name $kvSecretName - IncludeVersions - ErrorAction Stop).Id
385+ $osVersion = " "
386+ if (Get-AzureRmVMImage - Location $ResourceLocation - PublisherName " MicrosoftWindowsServer" - Offer " WindowsServer" - Sku " 2016-DataCenter-Core" - ErrorAction SilentlyContinue)
387+ {
388+ $osVersion = " 2016-DataCenter-Core"
389+ }
390+ elseif (Get-AzureRmVMImage - Location ResourceLocation - PublisherName " MicrosoftWindowsServer" - Offer " WindowsServer" - Sku " 2012-R2-Datacenter" - ErrorAction SilentlyContinue)
391+ {
392+ $osVersion = " 2012-R2-Datacenter"
393+ }
391394 $templateDeploymentName = " CanaryVMDeployment"
392395 $parameters = @ {" VMAdminUserName" = $VMAdminUserName ;
393396 " VMAdminUserPassword" = $VMAdminUserPass ;
394397 " ASCanaryUtilRG" = $CanaryUtilitiesRG ;
395398 " ASCanaryUtilSA" = $storageAccName ;
396399 " ASCanaryUtilSC" = $storageCtrName ;
397400 " vaultName" = $keyvaultName ;
401+ " windowsOSVersion" = $osVersion ;
398402 " secretUrlWithVersion" = $kvSecretId }
399403 if (-not (Test-AzureRmResourceGroupDeployment - ResourceGroupName $CanaryVMRG - TemplateFile .\azuredeploy.json - TemplateParameterObject $parameters ))
400404 {
401405 New-AzureRmResourceGroupDeployment - Name $templateDeploymentName - ResourceGroupName $CanaryVMRG - TemplateFile .\azuredeploy.json - TemplateParameterObject $parameters - Verbose - ErrorAction Stop
402406 }
407+ else
408+ {
409+ throw [System.Exception ] " Template validation failed. Please check for errors in your template"
410+ }
403411 }
404412
405413 $canaryVMList = @ ()
0 commit comments