我无法正常工作:电脑重新启动后,我的脚本将无法继续执行。
我已经注册了ScheduledJob,启动了我的工作流程。 工作流程包括在各个文件夹中使用参数/play=file.rec执行start.exe,然后在每次执行之间重新启动。 它不应并行执行。
这是我当前的代码版本,该代码可以运行,但在重新启动后不会恢复:
function Install-App {
Param ([PSObject]$folder)
#Locating .rec file
$recfile = @()
$recfile = (Get-ChildItem $folder.FullName -Recurse -File -Filter "*.rec")
#Executing start.exe in replay mode
$arg = "/play="""+$recfile+""""
$cmd = "$($folder.FullName)\start.exe"
Write-Output "Executing $cmd $arg"
& $cmd $arg
}
workflow Software_Workflow{
# #create an array
$wrkdir = @()
#Executing installation for each directory
$wrkdir =Get-ChildItem -Recurse -Directory
ForEach($d in $wrkdir){
Install-App -folder $d
Checkpoint-Workflow
Restart-Computer -Wait
}
Unregister-ScheduledJob -Name NewServerSetupResume
}
# Create the scheduled job properties
Write-Output "End of loading, setting parameters"
$user = "***"
$secpasswd = ConvertTo-SecureString "***" -AsPlainText -Force
$options = New-ScheduledJobOption -RunElevated -ContinueIfGoingOnBattery -StartIfOnBattery
$cred = New-Object System.Management.Automation.PSCredential ($user, $secpasswd)
$AtStartup = New-JobTrigger -AtStartup
# Register the scheduled job
Register-ScheduledJob -Name NewServerSetupResume -Credential $cred -Trigger $AtStartup -ScriptBlock {[System.Management.Automation.Remoting.PSSessionConfigurationData]::IsServerManager = $true; Import-Module PSWorkflow; Get-Job -Name NewServerSetupResume -State Suspend | Resume-Job} -ScheduledJobOption $options
# Execute the workflow as a new job
Software_Workflow -JobName InstallationWorkflow -PSPersist $True