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
相關文章
相關標籤/搜索