The creation of ADDS on Azure does not work irregularly
Description
I made my own version based on the script "VpnConnectedLab.ps1". If I start the script now it sometimes works and sometimes it doesn't. I can't find a regularity. I've done it about 15 times in the past few days and it worked in about 4-5 runs.
The error always occurs when the domain is set up on Azure-based VMs, and always at the same time.
Does somebody have any idea? How could I isolate the problem?
Expected behavior
Log:
Installing Root Domain Controllers
- Machines with RootDC role to be installed: 'AZTOADDC01'
- Waiting for machines to start up..
- Waiting for Root Domain Controllers to complete installation of Active Directory and restart.......done
- Root Domain Controllers have now restarted. Waiting for Active Directory to start up........
- Done
Installing Additional Domain Controllers
- Machines with DC role to be installed: 'AZTOADDC02'
- Waiting for machines to start up..
- Waiting for additional Domain Controllers to complete installation of Active Directory and restart.....done
- Additional Domain Controllers have now restarted. Waiting for Active Directory to start up...........
- Done
Starting remaining machines
- Waiting for machines to start up.....
- Done
Performing post-installations tasks defined for each machine
- Post-installations done
Actual behavior
Installing Root Domain Controllers
- Machines with RootDC role to be installed: 'AZTOADDC01'
- Waiting for machines to start up..
- Waiting for Root Domain Controllers to complete installation of Active Directory and restart.....................................................................................................Wait-LabVMRestart : The following machines have not restarted in the timeout of 60 minute(s): AZTOADDC01
In C:\Program Files\WindowsPowerShell\Modules\AutomatedLab\5.16.0\AutomatedLabADDS.psm1:935 Zeichen:9
+ Wait-LabVMRestart -ComputerName $machines.Name -StartMachines ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Wait-LabVMRestart
Steps to reproduce
$Tenant = 'xxxxxxxx.onmicrosoft.com'
$TenantID = ''
$SubscriptionID = ''
Disable-AzContextAutosave -Scope Process | Out-Null
$Account = Connect-AzAccount -TenantId $TenantID
If ($TenantID -eq $Account.Context.Tenant.Id){
Write-Verbose -Message ("Log in on Tenant '" + $Tenant + "' with Account '" + $Account.Context.Account.Id + "'")
}
$currentAzureContext = Get-AzContext
$tenantId = $currentAzureContext.Tenant.Id
$accountId = $currentAzureContext.Account.Id
$AzureAD = Connect-AzureAD -TenantId $tenantId -AccountId $accountId
$ActiveTenantName = (Get-AzureADDomain | Where-Object {($_.Name -like '*onmicrosoft*') -and ($_.Name -notlike '*mail.onmicrosoft*')}).Name
Write-Verbose -Message ("Log in on Azure AD '" + $ActiveTenantName + "' with Account '" + $AzureAD.Account.Id + "'")
$Context = Set-AzContext -Scope Process -Tenantid $Tenantid -SubscriptionId $SubscriptionID
$SubscriptionId = (Get-AzContext).Subscription.Id
$labs = @(
@{
labName = 'AzureOneSite'
labShortName = 'AZTO'
labSubnet = '10.25.0.0/16'
labRootDomain = 'lab.local'
labGateway = '10.25.1.1'
labDns1 = '10.25.1.10'
labDns2 ='10.25.1.11'
labLocation = 'West Europe'
labLocationShort = 'EUWE'
labUserName = 'Install'
labPassword = 'Somepa$$01'
}
)
$labSources = Get-LabSourcesLocation
$labDrive = "$Env:ProgramData\AutomatedLab\Labs" # Use the default path, if you use another path, some issue can happen
$labVMDrive = 'C:\AutomatedLabs-VMs' #this is the drive where to create the VMs
foreach ($lab in $labs.GetEnumerator()) {
# Create the folder path for the lab using Join-Path
$labPath = Join-Path -Path $labDrive -ChildPath $lab.labName
$labVMPath = Join-Path -Path $labVMDrive -ChildPath $lab.labName
# Create the target directory if it does not exist
if (-not (Test-Path $labPath)) { New-Item $labPath -ItemType Directory | Out-Null }
if (-not (Test-Path $labVMPath)) { New-Item $labVMPath -ItemType Directory | Out-Null }
New-LabDefinition -Name $lab.labName -DefaultVirtualizationEngine Azure
Add-LabAzureSubscription -Path ($labDrive + '\' + $lab.labName) -DefaultLocation $lab.labLocation
Sync-LabAzureLabSources -SkipIsos
Add-LabVirtualNetworkDefinition -Name $lab.labName -AddressSpace $lab.labSubnet
Add-LabDomainDefinition -Name $lab.labRootDomain -AdminUser Install -AdminPassword $lab.labPassword
Set-LabInstallationCredential -Username Install -Password $lab.labPassword
# First DC, the root domain gets a first domain controller
$DefaultParamDC = @{}
$DefaultParamDC['Network']= $lab.labName
$DefaultParamDC['ToolsPath']= "$labSources\Tools"
$DefaultParamDC['Gateway']= $lab.labGateway
$DefaultParamDC['DnsServer1']=$lab.labDns1
$DefaultParamDC['DnsServer2']=$lab.labDns2
$DefaultParamDC['DomainName']=$lab.labRootDomain
$DefaultParamDC['Memory']=512MB
$DefaultParamDC['OperatingSystem']='Windows Server 2016 Datacenter (Desktop Experience)'
$DefaultParamDC['AzureRoleSize']='Standard_B2ms'
$roles = Get-LabMachineRoleDefinition -Role RootDC @{
ForestFunctionalLevel = 'Default'
DomainFunctionalLevel = 'Default'
SiteName = $lab.labName
SiteSubnet = $lab.labSubnet
}
$postInstallActivity = @()
$postInstallActivity += Get-LabPostInstallationActivity -ScriptFileName PrepareRootDomain.ps1 -DependencyFolder $labSources\PostInstallationActivities\PrepareRootDomain
$postInstallActivity += Get-LabPostInstallationActivity -ScriptFileName 'New-ADLabAccounts 2.0.ps1' -DependencyFolder $labSources\PostInstallationActivities\PrepareFirstChildDomain
Add-LabMachineDefinition -Name ($lab.labShortName + 'ADDC01') -IpAddress 10.25.1.10 -Roles $roles -PostInstallationActivity $postInstallActivity @DefaultParamDC
# Second DC, the root domain gets a second domain controller
$roles = Get-LabMachineRoleDefinition -Role DC
Add-LabMachineDefinition -Name ($lab.labShortName + 'ADDC02') -IpAddress 10.25.1.11 -Roles $roles @DefaultParamDC
Install-Lab
Stop-LabVM -All -Wait
}
Environment details
PowerShell Version
Name Value
---- -----
PSVersion 5.1.17763.771
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.771
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
AutomatedLab components
Name Version
---- -------
AutomatedLab 5.16.0
AutomatedLab.Common 2.0.184
AutomatedLabDefinition 5.16.0
AutomatedLabNotifications 5.16.0
AutomatedLabUnattended 5.16.0
AutomatedLabWorker 5.16.0
Az components
Name Version
---- -------
AzSK 4.1.0
Az.Accounts 1.6.1
Az.Advisor 1.0.0
Az.Aks 1.0.1
Az.AnalysisServices 1.1.0
Az.ApiManagement 1.2.0
Az.ApplicationInsights 1.0.1
Az.Automation 1.3.1
Az.Batch 1.1.0
Az.Billing 1.0.0
Az.Cdn 1.3.0
Az.CognitiveServices 1.2.0
Az.Compute 2.4.1
Az.ContainerInstance 1.0.1
Az.ContainerRegistry 1.1.0
Az.DataFactory 1.1.3
Az.DataLakeAnalytics 1.0.0
Az.DataLakeStore 1.2.1
Az.DeploymentManager 1.0.0
Az.DevTestLabs 1.0.0
Az.Dns 1.1.1
Az.EventGrid 1.2.1
Az.EventHub 1.3.0
Az.FrontDoor 1.1.0
Az.HDInsight 2.0.0
Az.IotHub 1.2.0
Az.KeyVault 1.3.0
Az.LogicApp 1.3.0
Az.MachineLearning 1.1.0
Az.ManagedServices 1.0.0
Az.MarketplaceOrdering 1.0.0
Az.Media 1.1.0
Az.Monitor 1.2.1
Az.Network 1.12.0
Az.NotificationHubs 1.1.0
Az.OperationalInsights 1.3.2
Az.PolicyInsights 1.1.2
Az.PowerBIEmbedded 1.1.0
Az.RecoveryServices 1.4.3
Az.RedisCache 1.1.0
Az.Relay 1.0.1
Az.Resources 1.6.1
Az.ServiceBus 1.3.0
Az.ServiceFabric 1.1.1
Az.SignalR 1.0.2
Az.Sql 1.13.1
Az.Storage 1.5.1
Az.StorageSync 1.2.0
Az.StreamAnalytics 1.0.0
Az.TrafficManager 1.0.1
Az.Websites 1.4.0
AzTable 2.0.2
AzureAD 2.0.2.31
AzureAutomationAuthoringToolkit 0.2.4.2
AzureInformationProtection 1.54.33.0
So far I was not successful in reproducing this issue. I have to say that my network connection is extremely stable though. I don't know how much of a factor that is. I will be running a couple of additional labs, maybe something turns up.
One side note: You are using Add-LabAzureSubscription not as we intended. The parameter Path does not exist. You should use the persisted context and the name of your subscription like so:
Add-LabAzureSubscription -SubscriptionName MySub1 -DefaultLocationName Westeurope -AutoShutdownTime 20:00:00