New-Service

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-service?view=powershell-5.1

PS C:\Program Files\PowerShell\6.0.0-beta.6> New-Service -Name LISA_41_Dev_Batch -DisplayName LISA_41_Dev_Batch -BinaryP

athName D:\ChuckLu\GitForSvn\02.source_4.1.0.0\LISA.Batch\LISA.Batch.MonitorService\bin\Debug\LISA.Batch.MonitorService.
exe

Status Name DisplayName
------ ---- -----------
Stopped LISA_41_Dev_Batch LISA_41_Dev_Batch

PS C:\Program Files\PowerShell\6.0.0-beta.6> New-Service -Name LISA_50_Dev_Batch -DisplayName LISA_50_Dev_Batch -BinaryP
athName D:\ChuckLu\Git\Edenred\LISA_5.0.0.0\LISA.Batch\LISA.Batch.MonitorService\bin\Debug\LISA.Batch.MonitorService.exe

Status Name DisplayName
------ ---- -----------
Stopped LISA_50_Dev_Batch LISA_50_Dev_Batch

PS C:\Program Files\PowerShell\6.0.0-beta.6> cd D:\ChuckLu\Git\Edenred\LISA_5.0.0.0\LISA.FileExchange\LISA.FileExchange.
Service\bin\Debug
PS D:\ChuckLu\Git\Edenred\LISA_5.0.0.0\LISA.FileExchange\LISA.FileExchange.Service\bin\Debug> New-Service -Name LISA_50_
Dev_FileExchange -DisplayName LISA_50_Dev_FileExchange -BinaryPathName .\LISA.FileExchange.Service.exe

Status Name DisplayName
------ ---- -----------
Stopped LISA_50_Dev_Fil... LISA_50_Dev_FileExchange

记得加上startup type

  1. -StartupType
    New-Service -Name LISA_50_Dev_FileExchange -DisplayName LISA_50_Dev_FileExchange -BinaryPathName .\LISA.FileExchange.Service.exe -StartupType Manual
  2. New-Service -Name LISA_60_Dev_Batch -DisplayName LISA_60_Dev_Batch -BinaryPathName  .\LISA.Batch.MonitorService.exe -StartupType Manual

Get-Service

PS C:\Users\clu> help get-service

NAME
Get-Service

SYNTAX
Get-Service [[-Name] <string[]>] [-ComputerName <string[]>] [-DependentServices] [-RequiredServices] [-Include <str
ing[]>] [-Exclude <string[]>] [<CommonParameters>]

Get-Service -DisplayName <string[]> [-ComputerName <string[]>] [-DependentServices] [-RequiredServices] [-Include <
string[]>] [-Exclude <string[]>] [<CommonParameters>]

Get-Service [-ComputerName <string[]>] [-DependentServices] [-RequiredServices] [-Include <string[]>] [-Exclude <st
ring[]>] [-InputObject <ServiceController[]>] [<CommonParameters>]

ALIASES
gsv

REMARKS
Get-Help cannot find the Help files for this cmdlet on this computer. It is displaying only partial help.
-- To download and install Help files for the module that includes this cmdlet, use Update-Help.
-- To view the Help topic for this cmdlet online, type: "Get-Help Get-Service -Online" or
go to http://go.microsoft.com/fwlink/?LinkID=113332.

https://msdn.microsoft.com/powershell/reference/5.1/microsoft.powershell.management/Get-Service

Example

Get-Service -DisplayName FileExchange4.3_SourceCode

Get-Service | Where-Object {$_.name.Contains("LBS")} | Select name,DisplayName

Get-Service | Where-Object{$_.name.Contains("LFXSVC_")} | Select name,DisplayName

Get-Service | Where-Object {$_.name.Contains("LISA")} | Select Status,Name,DisplayName

Start-Service

PS C:\Users\clu> help start-service

NAME
Start-Service

SYNTAX
Start-Service [-InputObject] <ServiceController[]> [-PassThru] [-Include <string[]>] [-Exclude <string[]>] [-WhatIf
] [-Confirm] [<CommonParameters>]

Start-Service [-Name] <string[]> [-PassThru] [-Include <string[]>] [-Exclude <string[]>] [-WhatIf] [-Confirm] [<Co
mmonParameters>]

Start-Service -DisplayName <string[]> [-PassThru] [-Include <string[]>] [-Exclude <string[]>] [-WhatIf] [-Confirm]
[<CommonParameters>]

ALIASES
sasv

REMARKS
Get-Help cannot find the Help files for this cmdlet on this computer. It is displaying only partial help.
-- To download and install Help files for the module that includes this cmdlet, use Update-Help.
-- To view the Help topic for this cmdlet online, type: "Get-Help Start-Service -Online" or
go to http://go.microsoft.com/fwlink/?LinkID=113406.

https://msdn.microsoft.com/powershell/reference/5.1/microsoft.powershell.management/Start-Service

Example

Start-Service -Name "eventlog"

Start-Service -DisplayName FileExchange4.3_SourceCode

Restart-Service

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/restart-service?view=powershell-6

The Restart-Service cmdlet sends a stop message and then a start message to the Windows Service Controller for a specified service.

If a service was already stopped, it is started without notifying you of an error.

You can specify the services by their service names or display names, or you can use the InputObject parameter to pass an object that represents each service that you want to restart.

Stop-Service

PS C:\Users\clu> help stop-service

NAME
Stop-Service

SYNTAX
Stop-Service [-InputObject] <ServiceController[]> [-Force] [-NoWait] [-PassThru] [-Include <string[]>] [-Exclude <s
tring[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

Stop-Service [-Name] <string[]> [-Force] [-NoWait] [-PassThru] [-Include <string[]>] [-Exclude <string[]>] [-WhatIf
] [-Confirm] [<CommonParameters>]

Stop-Service -DisplayName <string[]> [-Force] [-NoWait] [-PassThru] [-Include <string[]>] [-Exclude <string[]>] [-W
hatIf] [-Confirm] [<CommonParameters>]

ALIASES
spsv

REMARKS
Get-Help cannot find the Help files for this cmdlet on this computer. It is displaying only partial help.
-- To download and install Help files for the module that includes this cmdlet, use Update-Help.
-- To view the Help topic for this cmdlet online, type: "Get-Help Stop-Service -Online" or
go to http://go.microsoft.com/fwlink/?LinkID=113414.

https://msdn.microsoft.com/powershell/reference/5.1/microsoft.powershell.management/Stop-Service

Example

Stop-Service -DisplayName FileExchange4.3_SourceCode

Stop-Service -DisplayName FileExchange4.3_SourceCode

通过任务管理器,强制终结服务

找到对应的exe,在进程中直接干掉。

Set-Service

PS C:\Users\clu> help set-service

NAME
Set-Service

SYNTAX
Set-Service [-Name] <string> [-ComputerName <string[]>] [-DisplayName <string>] [-Description <string>] [-StartupTy
pe <ServiceStartMode> {Boot | System | Automatic | Manual | Disabled}] [-Status <string> {Running | Stopped | Pause
d}] [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]

Set-Service [-ComputerName <string[]>] [-DisplayName <string>] [-Description <string>] [-StartupType <ServiceStartM
ode> {Boot | System | Automatic | Manual | Disabled}] [-Status <string> {Running | Stopped | Paused}] [-InputObject
<ServiceController>] [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]

ALIASES
None

REMARKS
Get-Help cannot find the Help files for this cmdlet on this computer. It is displaying only partial help.
-- To download and install Help files for the module that includes this cmdlet, use Update-Help.
-- To view the Help topic for this cmdlet online, type: "Get-Help Set-Service -Online" or
go to http://go.microsoft.com/fwlink/?LinkID=113399.

https://msdn.microsoft.com/powershell/reference/5.1/microsoft.powershell.management/Set-Service

Example

Set-Service -Name LBS_MONITOR -DisplayName Batch4.3_SourceCode

Delete Service

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-service?view=powershell-5.1

To delete a service, use Sc.exe, or use the Get-WmiObject cmdlet to get the Win32_Service object that represents the service and then use the Delete method to delete the service. The object that Get-Service returns does not have a delete method.

  1. PS C:\> sc.exe delete TestService 删除service之后,需要关闭任务管理器或service查看器,否则new-service的时候会出错
  2. - or -
  3. PS C:\> (Get-WmiObject win32_service -Filter "name='TestService'").delete()

This example shows two ways to delete the TestService service. The first command uses the delete option of Sc.exe. The second command uses the Delete method of the Win32_Service objects that Get-WmiObject returns.

Example

Get-WmiObject win32_service -Filter "name='LBS_MONITOR'" 加个括号,再调用delete

执行失败

__GENUS : 2
__CLASS : __PARAMETERS
__SUPERCLASS :
__DYNASTY : __PARAMETERS
__RELPATH :
__PROPERTY_COUNT : 1
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
ReturnValue : 2
PSComputerName :

执行成功

__GENUS : 2
__CLASS : __PARAMETERS
__SUPERCLASS :
__DYNASTY : __PARAMETERS
__RELPATH :
__PROPERTY_COUNT : 1
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
ReturnValue : 0
PSComputerName :

Remarks

PowerShell的命令,可以使用tab进行补全。

输入start-s然后tab键,两次tab后,会出现Start-Service。

然后空格,再输入服务的开头字母,再进行tab,可以通过自动补全,找到对应的服务

安装服务http://www.cnblogs.com/chucklu/p/7150420.html

https://social.technet.microsoft.com/wiki/contents/articles/36875.powershell-managing-service-s-using-wmi-cim-and-get-service-cmdlet.aspx

CIM

https://technet.microsoft.com/en-us/itpro/powershell/windows/cimcmdlets/get-ciminstance

Get-CimInstance -ClassName Win32_Service

Get-CimInstance -ClassName Win32_Service -Filter "name like 'L%'" | select Name,DisplayName,StartMode,State,StartName,SystemName,Description |Format-Table -AutoSize

批量停止service

Get-Service | Where-Object {$_.name.Contains("LISA_43")} | Stop-Service

PS C:\Users\clu\Desktop> Get-Service | Where-Object {$_.name.Contains("SQL2014")} | Select Status,Name,DisplayName

Status Name DisplayName
------ ---- -----------
Running MSOLAP$SQL2014 SQL Server Analysis Services (SQL2014)
Running MSSQL$SQL2014 SQL Server (SQL2014)
Running MSSQLFDLauncher$SQL2014 SQL Full-text Filter Daemon Launcher (SQL2014)
Running ReportServer$SQL2014 SQL Server Reporting Services (SQL2014)
Stopped SQLAgent$SQL2014 SQL Server Agent (SQL2014)

PS C:\Users\clu\Desktop> Get-Service | Where-Object {$_.name.Contains("SQL2014")} | Select Status,Name,DisplayName | Res
tart-Service
WARNING: Waiting for service 'SQL Server Reporting Services (SQL2014) (ReportServer$SQL2014)' to stop...
WARNING: Waiting for service 'SQL Server Reporting Services (SQL2014) (ReportServer$SQL2014)' to stop...
WARNING: Waiting for service 'SQL Server Reporting Services (SQL2014) (ReportServer$SQL2014)' to start...

PowerShell中和服务相关的命令的更多相关文章

  1. linux 软连接创建 压缩解压缩 linux的dns服务相关

    linux软连接创建 注意用绝对路径,语法如下 ln -s 目标文件绝对路径 软连接名字绝对路径 ln -s /小护士.txt /tmp/hs.txt 修改linux的PS1变量,命令提示符变量 PS ...

  2. DHCP服务相关实验

    一.DHCP 相关介绍 1.dhcp服务相关 软件名: dhcp #DHCP服务软件包 dhcp-common #DHCP命令软件包(默认已安装) 服务名: dhcpd #DHCP服务名 dhcrel ...

  3. Linux软件安装——服务管理的命令

    Linux软件安装——服务管理的命令 摘要:本文主要学习了Linux系统中服务管理的命令. service命令 service命令用于对系统服务进行管理,比如启动(start).停止(stop).重启 ...

  4. Linux系统之网络相关的命令

    Linux系统之网络相关的命令 网络概述 网络:通过通信介质和通信设备 将分布不同地点的两台或多台计算机,经过相应的程序实现通信switch 交换机router 路由器网络的功能:数据通信:利用网络传 ...

  5. Redis 键(key)相关的命令及其它命令的查看地址

    Redis 键(key) Redis 键命令用于管理 redis 的键. 语法 Redis 键命令的基本语法如下: redis 127.0.0.1:6379> COMMAND KEY_NAME ...

  6. Java的cmd配置(也即Java的JDK配置及相关常用命令)——找不到或无法加载主类 的解决方法

    Java的cmd配置(也即Java的JDK配置及相关常用命令) ——找不到或无法加载主类  的解决方法 这段时间一直纠结于cmd下Java无法编译运行的问题.主要问题描述如下: javac 命令可以正 ...

  7. window打开服务的dos命令

    window打开服务的dos命令   “开始”---> “运行”输入以下命令,或者Win + R,输入以下命令 对我比较有用的几个: 10. notepad--------打开记事本  31. ...

  8. Linux中mod相关的命令 内核模块化 mod相关命令都是用来动态加载内核模块/驱动程序模块

    Linux中mod相关的命令 内核模块化   mod相关命令都是用来动态加载内核模块/驱动程序模块 http://baike.baidu.com/link?url=lxiKxFvYm-UfJIxMjz ...

  9. Linux 相关scsi命令

    Linux 相关scsi命令 由于前段时间存储扩容,对存储操作较多,下面记录了常用的操作: lsscsi命令:显示scsi设备信息 #lsscsi [0:0:0:2]    disk    IBM   ...

随机推荐

  1. [CTSC2012]熟悉的文章(广义后缀自动机+二分答案+单调队列优化DP)

    我们对作文库建出广义后缀自动机.考虑用\(SAM\)处理出来一个数组\(mx[i]\),表示从作文的第\(i\)个位置向左最远在作文库中出现的子串的长度.这个东西可以在\(SAM\)上跑\(trans ...

  2. Spring学习总结(14)——Spring10种常见异常解决方法

    在程序员生涯当中,提到最多的应该就是SSH三大框架了.作为第一大框架的Spring框架,我们经常使用. 然而在使用过程中,遇到过很多的常见异常,我在这里总结一下,大家共勉. 一.找不到配置文件的异常 ...

  3. SVN学习总结(2)——SVN冲突解决

    在我们用VS进行项目合作开发的过程中,SVN的提交控制是至关重要的,大家不可避免的都遇到过SVN冲突的问题,开发的时候,应该认真学习SVN的知识,减少冲突,集中时间放在开发上. 解决冲突有三种方式: ...

  4. Qt之QToolButton

    简述 QToolButton类提供了用于命令或选项可以快速访问的按钮,通常可以用在QToolBar里面. 工具按钮和普通的命令按钮不同,通常不显示文本,而显示图标. 简述 详细描述 常用接口 更多参考 ...

  5. hdu4089Activation 概率dp

    //一条队列对于第一个人的情况 //概率p1:队列保持不变 //p2:第一个人到队尾 //p3:第一个人出队 //p4:系统崩溃 //队列中有N个人,Tomato 在第M位置,求系统崩溃.Tomato ...

  6. Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD

    Build.VERSION.SDK_INT是系统的版本,Build.VERSION_CODES.GINGERBREAD是版本号. 到VERSION.SDK_INT不禁诧异,这是何物?! 看API的定义 ...

  7. zzulioj--1776--和尚特烦恼2——第几个素数(技巧模拟)

    1776: 和尚特烦恼2--第几个素数 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 267  Solved: 100 SubmitStatusWeb ...

  8. CSS提高渲染速度的写法

    写CSS的习惯,决定页面渲染速度的快慢,这一点在脑残的IE里更加明显.养成良好的习惯,乃至形成规范,会让你的页面更快速的加载,用户体验度更高,下面是零度逍遥总结的一些提高CSS渲染速度的写法,供大家参 ...

  9. Java 类和对象7

    创建一个三角形类,成员变量三边,方法求周长,创建类主类A来测试它. public class sanjiaoxing { private double a; private double b; pri ...

  10. Java类和对象4

    编写Java应用程序.首先,定义一个Print类,它有一个方法void output(intx),如果x的值是1,在控制台打印出大写的英文字母表:如果x的值是2,在控制台打印出小写的英文字母表.其次, ...