PowerShell工做流学习-4-工做流中重启计算机

关键点:web

a)工做流中从新启动计算机,请使用Restart-Computer的Wait参数,Wait参数不只适用于本地计算机,也适用于远程计算机。blog

b)重启运行工做流的计算机,手工恢复请使用Resume-Job,自动恢复请在运行工做流的计算机上建立计划任务、当工做流运行完成后注销该计划任务。ip

 

例a)workflow

workflow Test-WFRestartServer 
{
 Param
    (
        [string]$ServerName="localhost"
    )
  Get-Process -Name WMSvc -PSComputerName $ServerName
  Restart-Computer -PSComputerName $ServerName  -Wait
  Set-Content -Path "\\$ServerName\c\WFTest\1.txt" -Value 123
}

ls '\\website14\c\WFTest\1.txt'
Test-WFRestartServer -ServerName "website14"
ls '\\website14\c\WFTest\1.txt'


ls : 找不到路径“\\website14\c\WFTest\1.txt”,由于该路径不存在。
所在位置 行:12 字符: 1
+ ls '\\website14\c\WFTest\1.txt'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (\\website14\c\WFTest\1.txt:String) [Get-ChildItem], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
 

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id  SI ProcessName                          PSComputerName                     
-------  ------    -----      ----- -----   ------     --  -- -----------                          --------------                     
    255      50    20480      19768   515     0.25   9280   0 WMSvc                                website14                       

LastWriteTime : 2017/7/6 12:55:47
Length        : 5
Name          : 1.txt

 

例b:string

workflow Test-WFRestartServer { Param    (        [string]$ServerName="localhost"    )  Get-Process -Name WMSvc -PSComputerName $ServerName  Restart-Computer -PSComputerName $ServerName  -Wait  ls '\\localhost\c\WFTest\1.txt'}$AtStartup = New-JobTrigger -AtStartup
Register-ScheduledJob -Name ResumeWorkflow -Trigger $AtStartup -ScriptBlock {Import-Module PSWorkflow; Get-Job ComputerSetup -State Suspended | Resume-Job}
Test-WFRestartServer Unregister-ScheduledJob -Name ResumeWorkflow



Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id  SI ProcessName                          PSComputerName                     -------  ------    -----      ----- -----   ------     --  -- -----------                          --------------                         251      47    20176      18124   516     8.34   1960   0 WMSvc                                localhost                          LastWriteTime  : 2017/7/6 16:36:34Length         : 5Name           : 1.txtPSComputerName : localhost
相关文章
相关标签/搜索