Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 从最后一个执行点重新启动系统后,继续执行powershell脚本_Windows_Powershell_Ps1 - Fatal编程技术网

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

Windows 从最后一个执行点重新启动系统后,继续执行powershell脚本,windows,powershell,ps1,Windows,Powershell,Ps1,我想做什么? 按以下顺序在本地磁盘中创建四个文件。 注意:在我的本地机器上,而不是在任何远程服务器上 要创建的三个文件 重新启动系统 在系统启动时创建另一个文件 我使用过的脚本。 get-job | remove-job -Force function create-file { Param ([string] $a) $p = "D:\" + $a Write-Host $p if (!(Test-Path $p)) { New-Item -p

我想做什么?

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

  • 要创建的三个文件
  • 重新启动系统
  • 在系统启动时创建另一个文件
我使用过的脚本。


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是个新手


提前感谢。

先安排作业,然后在不等待的情况下重新启动。

先安排作业,然后在不等待的情况下重新启动