$scriptName = $MyInvocation.MyCommand.Name $logFile = "C:\Logs\${scriptName}_log.txt" Start-Transcript -Path $logFile -Append while ($true) { try { Write-Host "[INFO] Checking if domain is ready" Get-ADDomain break } catch { Write-Host "[INFO] Sleeping for 60s" Start-Sleep -Seconds 60 } } Write-Host "[INFO] Domain is ready" Stop-Transcript