zoukankan      html  css  js  c++  java
  • PowerShell工作流学习-4-工作流中重启计算机

    关键点:

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

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

    例a)

    workflow Test-WFRestartServer 
    {
     Param
        (
            [string]$ServerName="localhost"
        )
      Get-Process -Name WMSvc -PSComputerName $ServerName
      Restart-Computer -PSComputerName $ServerName  -Wait
      Set-Content -Path "\$ServerNamecWFTest1.txt" -Value 123
    }
    
    ls '\website14cWFTest1.txt'
    Test-WFRestartServer -ServerName "website14"
    ls '\website14cWFTest1.txt'
    
    
    ls : 找不到路径“\website14cWFTest1.txt”,因为该路径不存在。
    所在位置 行:12 字符: 1
    + ls '\website14cWFTest1.txt'
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (\website14cWFTest1.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:

    workflow Test-WFRestartServer 
    {
     Param
        (
            [string]$ServerName="localhost"
        )
      Get-Process -Name WMSvc -PSComputerName $ServerName
      Restart-Computer -PSComputerName $ServerName  -Wait
      ls '\localhostcWFTest1.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:34
    Length         : 5
    Name           : 1.txt
    PSComputerName : localhost
  • 相关阅读:
    文件内部写入及读取(参考疯狂安卓讲义)
    API内部文件读取
    内部存储文件(读)
    内部存储文件(写)
    短信发送器(1.0版)
    按钮点击的三种方法及推广
    struts标签错误:Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"
    java中16进制转换10进制
    java project转变成java web project
    oracle,sqlserver,mysql常见数据库jdbc连接
  • 原文地址:https://www.cnblogs.com/lixiaonuohao/p/7127129.html
Copyright © 2011-2022 走看看