$path=(Get-Item -Path '.\' -Verbose).FullName $isoDir=$path+"\Windows11.iso" $opDir="C:\Windows11Setup" $arguments=@("x", "-y", "`"$isoDir`"", "-o`"$opDir`""); $param1=$args[0] $fpSwitch=$null $7zipPath = ${env:ProgramFiles(x86)}+"\DesktopCentral_Agent\bin\7z.exe" If( -not (Test-Path -Path $isoDir -PathType Leaf)){exit 2} If( -not ([string]::IsNullOrEmpty($param1))) { $fpSwitch=$param1 } Else { $fpSwitch="/auto upgrade /DynamicUpdate disable /ShowOOBE none /quiet /noreboot /compat IgnoreWarning /BitLocker TryKeepActive /EULA accept" } $archi=(Get-WmiObject Win32_OperatingSystem).OSArchitecture If($archi -like '64-bit') { $ex =start-process -FilePath $7zipPath -ArgumentList $arguments -wait -PassThru -WindowStyle Hidden } Else { exit = 216 } $WimFile = $opDir+"\sources\install.wim" $ESDFile = $opDir+"\sources\install.esd" If(Test-Path -Path $WimFile -PathType Leaf) { $OS = (get-windowsimage -imagepath $WimFile -index 1).imagename } ELSEIf(Test-Path -Path $ESDFile -PathType Leaf) { $OS = (get-windowsimage -imagepath $ESDFile -index 1).imagename } ELSE { exit 1813 } if( -not ($OS.Contains("Windows 11"))) { exit 50007 } $ts = New-TimeSpan -Days 0 -Hours 0 -Minutes 2 $setTime = (Get-Date) + $ts $fTime = $setTime.ToString('HH:mm') $Trigger= New-ScheduledTaskTrigger -At $fTime -Once $User= "NT AUTHORITY\SYSTEM" $Action= New-ScheduledTaskAction -Execute "C:\Windows11Setup\setup.exe" -Argument $fpSwitch; If($ex.ExitCode -eq 0) { Register-ScheduledTask -TaskName "Windows 11 FeaturePack Upgrade (DC)" -Trigger $Trigger -User $User -Action $Action -RunLevel Highest -Force | Out-Null Start-Sleep -s 120 $exCode = (Get-ScheduledTask | Where { $PSITEM.TaskName -eq "Windows 11 FeaturePack Upgrade (DC)"} | get-ScheduledTaskInfo).LastTaskResult While(($exCode -eq 267011) -or ($exCode -eq 267009)) { $exCode = (Get-ScheduledTask | Where { $PSITEM.TaskName -eq "Windows 11 FeaturePack Upgrade (DC)"} | get-ScheduledTaskInfo).LastTaskResult Start-Sleep -s 120 } Unregister-ScheduledTask -TaskName "Windows 11 FeaturePack Upgrade (DC)" -Confirm:$false } $exCode = '{0:X}' -f $exCode $exCode = [bigint]::Parse($exCode, 'AllowHexSpecifier') Write-Output $exCode exit $exCode