Restart-ServiceEx.psm1
示例
- C:PS> import-module c:\ps\modules\Restart-ServiceEx.psm1
- C:PS> Restart-ServiceEx AdobeARMservice,DcomLaunch -ComputerName server01
- Stopping 'Adobe Acrobat Update Service' on SERVER01.
- 'Adobe Acrobat Update Service' on SERVER01 was stopped successfully!
- Starting 'Adobe Acrobat Update Service' on server01.
- 'Adobe Acrobat Update Service' on SERVER01 was started successfully!
- Stopping 'DCOM Server Process Launcher' on SERVER01
- WARNING: Service Cannot Accept Control
Restart-ServiceEx.psm1
- function Restart-ServiceEx {
- [CmdletBinding(DefaultParameterSetName="Name")]
- param(
- [Parameter(ParameterSetName="Name",Position=0,ValueFromPipeline=$true)]
- [string[]]$Name,
- [Parameter(ParameterSetName="DisplayName",Position=0,ValueFromPipeline=$true)]
- [string[]]$DisplayName,
- [string[]]$ComputerName=$env:COMPUTERNAME
- )
- # create list of clear text error messages
- $ErrorCode = 'Success,Not Supported,Access Denied,Dependent Services Running,Invalid Service Control'
- $ErrorCode += ',Service Cannot Accept Control, Service Not Active, Service Request Timeout'
- $ErrorCode += ',Unknown Failure, Path Not Found, Service Already Running, Service Database Locked'
- $ErrorCode += ',Service Dependency Deleted, Service Dependency Failure, Service Disabled'
- $ErrorCode += ',Service Logon Failure, Service Marked for Deletion, Service No Thread'
- $ErrorCode += ',Status Circular Dependency, Status Duplicate Name, Status Invalid Name'
- $ErrorCode += ',Status Invalid Parameter, Status Invalid Service Account, Status Service Exists'
- $ErrorCode += ',Service Already Paused'
- $Services = @()
- switch($PSCmdlet.ParameterSetName) {
- "Name" {
- $Name | % {
- $s = Get-WmiObject win32_service -ComputerName $ComputerName -Filter "Name=`"$_`""
- if($s) { $Services += $s }
- }
- if(!$Services) { return "Can not found any service of the name '{0}'" -f $($Name -join "','") }
- }
- "DisplayName" {
- $DisplayName | % {
- $s = Get-WmiObject win32_service -ComputerName $ComputerName -Filter "DisplayName=`"$_`""
- if($s) { $Services += $s }
- }
- if(!$Services) { return "Can not found any service of the displayname '{0}'" -f $($DisplayName -join "','") }
- }
- }
- for($i=0; $i -lt $Services.length; $i++) {
- if($Services[$i].Started) {
- Write-Host $("Stopping '{0}' on {1}" -f $Services[$i].DisplayName,$Services[$i].__SERVER) -NoNewline
- $rv = $Services[$i].StopService().ReturnValue
- if ($rv) { Write-Host "";Write-Warning $("{0}`n" -f $ErrorCode.Split(',')[$rv]);continue }
- do {
- Write-Host "." -NoNewline
- Start-Sleep -s 10
- $service = Get-WmiObject win32_service -ComputerName $Services[$i].__SERVER -Filter "DisplayName=`"$($Services[$i].DisplayName)`""
- }while($service.State -ne "Stopped")
- Write-Host $("`n'{0}' on {1} was stopped successfully!" -f $Services[$i].DisplayName,$Services[$i].__SERVER)
- Write-Host $("Starting '{0}' on {1}" -f $Services[$i].DisplayName,$Services[$i].__SERVER) -NoNewline
- $rv = $Services[$i].StartService().ReturnValue
- if ($rv) { Write-Host "";Write-Warning $("{0}`n" -f $ErrorCode.Split(',')[$rv]);continue }
- do {
- Write-Host "." -NoNewline
- Start-Sleep -s 10
- $service = Get-WmiObject win32_service -ComputerName $Services[$i].__SERVER -Filter "DisplayName=`"$($Services[$i].DisplayName)`""
- }while($service.State -ne "Running")
- Write-Host $("`n'{0}' on {1} was started successfully!`n" -f $Services[$i].DisplayName,$Services[$i].__SERVER)
- }
- else {
- Write-Host $("Starting '{0}' on {1}" -f $Services[$i].DisplayName,$Services[$i].__SERVER) -NoNewline
- $rv = $Services[$i].StartService().ReturnValue
- if ($rv) { Write-Host "";Write-Warning $("{0}`n" -f $ErrorCode.Split(',')[$rv]);continue }
- do {
- Write-Host "." -NoNewline
- Start-Sleep -s 10
- $service = Get-WmiObject win32_service -ComputerName $Services[$i].__SERVER -Filter "DisplayName=`"$($Services[$i].DisplayName)`""
- }while($service.State -ne "Running")
- Write-Host $("`n'{0}' on {1} was started successfully!`n" -f $Services[$i].DisplayName,$Services[$i].__SERVER)
- }
- }
- }
- Export-ModuleMember -function Restart-ServiceEx
Restart-ServiceEx.psm1的更多相关文章
- OpenGL ES 3.0: 图元重启(Primitive restart)
[TOC] 背景概述 在OpenGL绘制图形时,可能需要绘制多个并不相连的图形.这样的情况下这几个图形没法被当做一个图形来处理.也就需要多次调用 DrawArrays 或 DrawElements. ...
- 关于点击Invalidate Caches/Restart禁止插件后,重新加载--Android Studio
1:47:27 Plugin Error Problems found loading plugins: Plugin "Google Analytics Uploader" wa ...
- Tomcat重启脚本restart.sh停止脚本stop.sh
Tomcat重启脚本restart.sh停止脚本stop.sh Tomcat本身提供了 startup.sh(启动)shutdown.sh(关闭)脚本,我们在部署中经常会出现死进程形象,无法杀掉进程需 ...
- ubuntu14.04服务版/etc/init.d/smbd restart无效的解决方法
刚装的ubuntu14.04配置完smbd发现service或者/etc/init.d/smbd restart都不显示任何输出,也没起作用 echo $?输出1,查看脚本发现 if init_is_ ...
- shell来start、stop、restart应用程序模板
这里使用shell中的case语法: case分支语句格式如下: case $变量名 in 模式1) 命令列表 ;; 模式2) 命令列表 ;; *) ;; esac case行尾必须为单词“in”,每 ...
- 虚拟机service network restart没有反应解决方法
一般我们新copy的虚拟机或新克隆的虚拟机第一次启动时都会出现没有ip地址的情况: [root@zejin243 network-scripts]# ifconfig lo Link ...
- ADB not responding. If you'd like to retry, then please manually kill "adb.exe" and click 'Restart'
ADB not responding. If you'd like to retry, then please manually kill "adb.exe" and click ...
- configs for postgresql restart and postgresql reload
-- configs requiring postgresql restart select name, setting, context from pg_settings where context ...
- 把Nginx加为系统服务(service nginx start/stop/restart)
1.编写脚本,名为nginx #!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - ...
- ADB not responding. You can wait more,or kill"abd.exe" process manually and click 'Restart'
在使用Android Studio进行开发的过程中,有时候编译运行时,会出现如下提示: ADB not responding. You can wait more,or kill"abd.e ...
随机推荐
- Uva_11916 Emoogle Grid
题目链接 题意: 有个N X M的棋盘, 有K种颜色, 有B个不可涂色的位置, 共有R种涂色方案. 1)每个可涂色的位置必须涂上一种颜色 2)不可涂色位置不能涂色 3)每个位置必须从K种颜色中选出一种 ...
- iOSシステム構成の纏め
iOSのアーキテクチャ a) iOSのアーキテクチャは階層化されている最上位レベルでは.iOSはそれが稼働しているハードウェアとアプリケーションの間の仲介役を果たします.アプリケーションが ...
- webserver<1>
1. 实现基础的信号处理 sigaction使用前一定内存清零 2. 实现基础的进程模型 wait 等待子进程结束 #include <stdio.h> #include <unis ...
- app内购提示,您已购买此商品,但未下载
出现这样的问题,是支付没有finish造成的,一般在支付过程中断网了,下次再购买同一商品的时候就会出现这样的问题, 解决办法,在点击购买的时候判断支付队列中是否有为finish的商品,若有,则进行处理 ...
- 【Ireport】利用Ireport5.2的table组件迅速制作表格导出pdf
转载请注明网址.Ireport table dataset Ireport在半年前还是4.7,今天无意发现,居然出到了5.2就搞一把. 首先,去下载Ireport,并进行安装.这个我就不演示了.下载完 ...
- iPhone手机VPN设置
如果iPhone,iPad游戏或软件服务器在国外不能用,就需要设置VPN了. 如果是为了解除公司上网策略限制,或者为了上Google,Facebook,都可以通过设置VPN实现. 要使用VPN需要到V ...
- ServletContextListener作用(转)
ServletContext 被 Servlet 程序用来与 Web 容器通信.例如写日志,转发请求.每一个 Web 应用程序含有一个Context,被Web应用内的各个程序共享.因为Context可 ...
- [LeetCode#265] Paint House II
Problem: There are a row of n houses, each house can be painted with one of the k colors. The cost o ...
- TC358746AXBG/748XBG 桥接器说明
为什么需要这个mipi csi-2 bridge 芯片,由于我们用的sensor 芯片是美光的MT9m021,这颗芯片并不支持MIPI 下面是网上摘录的说明可能解释这个问题: Because of t ...
- 突破LVS瓶颈,LVS Cluster部署(OSPF + LVS) - lxcong的运维技术 - 开源中国社区
突破LVS瓶颈,LVS Cluster部署(OSPF + LVS) - lxcong的运维技术 - 开源中国社区 突破LVS瓶颈,LVS Cluster部署(OSPF + LVS)