zoukankan      html  css  js  c++  java
  • powershell 远程重启/关闭服务器

    powershell 远程重启/关闭服务器

    #启动winrm

    PS C:Windowssystem32> winrm quickconfig -q

    #设置信任主机

    PS C:Windowssystem32> set-Item WSMan:localhostClientTrustedHosts -Value  192.168.1.2 

    #登录验证

    PS C:Windowssystem32> $c = Get-Credential 

    #设置要关闭的服务器的名称

    PS C:Windowssystem32> $cname = "192.168.1.2"

    #建立一个连接

    PS C:Windowssystem32> $ser1=New-PSSession -ComputerName $cname -Credential $c

    #重起服务器

    PS C:Windowssystem32> invoke-command -session $ser1 -scriptblock {Shutdown -r -t 0}

    下次再用,只要下面的即可

    $c = Get-Credential
    $cname = "192.168.1.2"
    $ser1=New-PSSession -ComputerName $cname -Credential $c
    invoke-command -session $ser1 -scriptblock {Shutdown -r -t 0}

    { } 内可以做你想做的事情,

    {net start w32Time  } #启动时间服务

    {dir} #查看当前文件

    {net stop w32Time} #停止时间服务

  • 相关阅读:
    2016huasacm暑假集训训练四 递推_A
    2016huasacm暑假集训训练三 G
    2016huasacm暑假集训训练三 F
    今年暑假不AC
    Who's in the Middle
    The Suspects
    食物链
    抓牛问题
    士兵队列训练问题
    H
  • 原文地址:https://www.cnblogs.com/endv/p/7225370.html
Copyright © 2011-2022 走看看