如何使用PowerShell在远程计算机中启动/停止多个服务 [英] How to start/stop multiple services in a remote machine using powershell

查看:268
本文介绍了如何使用PowerShell在远程计算机中启动/停止多个服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI 

i wrote some script for stop and start for a single service ..

#Change this values to suit your needs:

$SvcName = 'Spooler'
$SvrName = 'remotePC'

#Initialize variables:
[string]$WaitForIt = ""
[string]$Verb = ""
[string]$Result = "FAILED"
$svc = (get-service -computername $SvrName -name $SvcName)
Write-host "$SvcName on $SvrName is $($svc.status)"
Switch ($svc.status) {
    'Stopped' {
        Write-host "Starting $SvcName..."
        Write-host "$SvcName is started"
        $Verb = "start"
        $WaitForIt = 'Running'
        $svc.Start()}
    'Running' {
        Write-host "Stopping $SvcName..."
          Write-host "$SvcName is stopped"
        $Verb = "stop"
        $WaitForIt = 'Stopped'
        $svc.Stop()}
    Default {
        Write-host "$SvcName is $($svc.status).  Taking no action."}
        
}

this script is fine for stop/start for one windows servcie . but i want to start/stop multiple services at a time in one server .

plz help some one 





我尝试了什么:



i尝试了一项服务,它正在成功运作,我想要一次停止/启动多个服务。



What I have tried:

i tried for one service it is working successfully and i want to stop/start for multiple services at a time .

推荐答案

SvcName = ' 假脱机程序
SvcName = 'Spooler'


SvrName = ' remotePC '

#Initialize变量:
[ string ]
SvrName = 'remotePC' #Initialize variables: [string]


WaitForIt =
[ string ]
WaitForIt = "" [string]


这篇关于如何使用PowerShell在远程计算机中启动/停止多个服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆