I'm not sure this would be something that fits under the core psake module. Its strength is really providing a build harness environment with a nice dependency graphing moel. However, I have used psake for not only routine builds but also for deployments and bootstraping environment setups. I have ran into a couple scenarios where I needed to perform a restart and continue the setup psake build afterwards.For example, I have a task that downloads and installs critical windows updates. Here is an example of the task:
Task Check-And-Install-Updates -description "Checks for critical updates and installs them. Will Reboot if necessary."{
if( Test-Path "$env:appdata\Microsoft\Windows\Start Menu\Programs\Startup\bootstrap-post-restart.bat") {
remove-item "$env:appdata\Microsoft\Windows\Start Menu\Programs\Startup\bootstrap-post-restart.bat"
}
Write-Output "Downloading and installing any critical updates. Will reboot if necessary..."
& \\tkfiltoolbox\tools\23649\3.0.37.2319\critfix.exe /restart none
if($lastexitcode -eq 3010) { #Restart needed
New-Item "$env:appdata\Microsoft\Windows\Start Menu\Programs\Startup\bootstrap-post-restart.bat" -type file -force -value "c:\bootstrap\psake\psake.ps1 $tasklist -Properties @{TemplateWorkspace=$TemplateWorkspace;SourcePath=$SourcePath;BinariesPath=$BinariesPath;SqlInstanceName=$SqlInstanceName;Log=$Log;zone=$zone}"
Write-Output "Restart Required. Restarting now..."
Restart-Computer -force
}
}
If I need to restart, I create a batch file in the windows startup directory that will call psake with the same params it was called with. Almost all of my tasks have PreCondition params that check to see if the task needs to run and avoids duplicate task execution so the need to resume from where I left is mitigated by that.