@@ -88,6 +88,28 @@ New-Item -Path $Env:MHBoxDemoPageDir -ItemType directory -Force
8888
8989Start-Transcript - Path $Env: MHBoxLogsDir \Bootstrap.log
9090
91+ Write-Host " Invocation line:"
92+ Write-Host $MyInvocation.Line
93+
94+ Write-Host " Bound parameters:"
95+ $PSBoundParameters.GetEnumerator () | Sort-Object Name | ForEach-Object {
96+ Write-Host " $ ( $_.Key ) = $ ( $_.Value ) "
97+ }
98+
99+ # Early Az init - before any module install/update in this session
100+ $ErrorActionPreference = ' Stop'
101+
102+ Disable-AzContextAutosave - Scope Process | Out-Null
103+
104+ Import-Module Az.Accounts - Force
105+ Import-Module Az.Resources - Force
106+ Import-Module Az.KeyVault - Force
107+
108+ Connect-AzAccount - Identity - Tenant $tenantId - Subscription $subscriptionId | Out-Null
109+ Set-AzContext - Subscription $subscriptionId | Out-Null
110+
111+ Write-Host " Az context initialized successfully"
112+
91113# Set SyncForegroundPolicy to 1 to ensure that the scheduled task runs after the client VM joins the domain
92114Set-ItemProperty " HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" " SyncForegroundPolicy" 1
93115
@@ -110,8 +132,6 @@ foreach ($module in $modules) {
110132}
111133
112134# Add Key Vault Secrets
113- Connect-AzAccount - Identity
114-
115135$DeploymentProgressString = " Started bootstrap-script..."
116136
117137$tags = Get-AzResourceGroup - Name $resourceGroup | Select-Object - ExpandProperty Tags
@@ -336,10 +356,10 @@ if ($flavor -eq "ITPro") {
336356 Register-ScheduledTask - TaskName " MHServersLogonScript" - User $adminUsername - Action $Action - RunLevel " Highest" - Force
337357}
338358
339- # Disabling Windows Server Manager Scheduled Task
340- Get-ScheduledTask - TaskName ServerManager | Disable-ScheduledTask
359+ # Disabling Windows Server Manager Scheduled Task
360+ Get-ScheduledTask - TaskName ServerManager | Disable-ScheduledTask
341361
342- if ($flavor -eq " ITPro" ) {
362+ if ($flavor -eq " ITPro" ) {
343363
344364 Write-Header " Installing Hyper-V"
345365
@@ -349,14 +369,13 @@ if ($flavor -eq "ITPro") {
349369 Enable-WindowsOptionalFeature - Online - FeatureName VirtualMachinePlatform - NoRestart
350370 Install-WindowsFeature - Name Hyper- V - IncludeAllSubFeature - IncludeManagementTools - Restart
351371
352- }
353-
354- # Clean up Bootstrap.log
355- Write-Host " Clean up Bootstrap.log"
356- Stop-Transcript
357- $logSuppress = Get-Content $Env: MHBoxLogsDir \Bootstrap.log | Where-Object { $_ -notmatch " Host Application: $ScheduledTaskExecutable " }
358- $logSuppress | Set-Content $Env: MHBoxLogsDir \Bootstrap.log - Force
372+ }
359373
374+ # Clean up Bootstrap.log
375+ Write-Host " Clean up Bootstrap.log"
376+ Stop-Transcript
377+ $logSuppress = Get-Content $Env: MHBoxLogsDir \Bootstrap.log | Where-Object { $_ -notmatch " Host Application: $ScheduledTaskExecutable " }
378+ $logSuppress | Set-Content $Env: MHBoxLogsDir \Bootstrap.log - Force
360379
361380# Restart computer
362- Restart-Computer
381+ Restart-Computer
0 commit comments