I don't have any SCCM experience, but from a server support perspective, I would use a temporary file to serve as a flag to tell the script which function it needs to process. The main question would be how the script gets restarted after the reboot. If you can do that with SCCM, then great. Otherwise the script would need to create a scheduled task that runs at system startup to complete the install.
Here's a framework in Powershell that might help you. It uses C:\Windows\Temp for the file location. Change that to suit your requirements.
Start-Transcript -append -Path ("$($env:SystemRoot)\temp\SccmScript-{0}.log" -f (get-date -format "yyyyMMdd" )) # This is your log file
Function Phase1 {
"This is Phase1."
"Do what you need to do here."
"Do something here to cause the script to be executed after the reboot. Create a scheduled task maybe?"
"Phase1 complete." | Out-File $FlagFile
"Schedule reboot here."
}
Function Phase2 {
"This is Phase2."
"This code runs after Phase1 has run and the machine has rebooted."
"Do what you need to do here."
"Delete the scheduled task here?????"
"Delete the flag file here?????"
"Phase2 complete." | Out-File $FlagFile
}
$FlagFile = $env:SystemRoot + "\temp\SCCM.flg"
"Our flag file is $FlagFile"
if ((Test-Path $FlagFile) -eq $false) {
"File does not exist. Perform phase 1."
Phase1 # Call the phase1 code.
} elseif ((Get-Content -Path $FlagFile) -match 'Phase2') {
"Error! I guess."
"Our flag file indicates that both Phase1 and Phase2 have completed."
"Does a scheduled task need to be deleted?"
"Should the flag file be deleted?"
"Maybe warn someone."
} else {
Phase2 # Call the phase2 code.
}
Stop-Transcript