繁体   English   中英

系统从上一个执行点重新启动后继续 powershell 脚本执行

[英]Continue powershell script execution after system restart from last execution point

我想做什么?

按以下顺序在本地磁盘中创建四个文件。 注意:在我的本地机器上,而不是在任何远程服务器上。

  • 创建三个文件
  • 重启系统
  • 在系统启动时创建另一个文件

我用过的脚本。


get-job | remove-job -Force

function create-file {
   Param ([string] $a)
   $p = "D:\" + $a
   Write-Host $p
   if (!(Test-Path $p))
   {
      New-Item -path D:\$a -type "file" -value "my new text"
      Write-Host "Created new file and text content added"
   }
   else
   {
     Add-Content -path D:\$a -value "new text content"
     Write-Host "File already exists and new text content added"
   }
}
Workflow New-ServerSetup
{
   create-file "one.txt"
   create-file "two.txt"
   create-file "three.txt"
   Restart-Computer -ComputerName $env:COMPUTERNAME -Wait
   Start-Sleep -Seconds 7
   create-file "four.txt"
   Unregister-ScheduledJob -Name NewServerSetupResume
}
$adm = "####"
$pwd = ConvertTo-SecureString -String "####" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($adm, $pwd)
$AtStartup = New-JobTrigger -AtStartup
Register-ScheduledJob -Name NewServerSetupResume -Credential $cred -Trigger $AtStartup -ScriptBlock {Import-Module PSWorkflow; Get-Job -Name NewSrvSetup -State Suspended | Resume-Job}

New-ServerSetup -JobName NewSrvSetup

我面临的问题

  • 执行返回无法等待本地计算机重新启动

如果有任何错误给我带来负担,我是 powershell 的新手。

提前致谢。

首先安排作业,然后重新启动,无需等待。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM