您现在的位置是:网站首页> 编程资料编程资料
Powershell小技巧之使用WMI测试服务响应_PowerShell_
2023-05-26
331人已围观
简介 Powershell小技巧之使用WMI测试服务响应_PowerShell_
测试一个服务是否有响应,有一个好办法。首先,使用WMI查询你指定的服务,WMI中可以返回构成它进程的ID。
function Test-ServiceResponding($ServiceName) { $service = Get-WmiObject -Class Win32_Service -Filter "Name='$ServiceName'" $processID = $service.processID $process = Get-Process -Id $processID $process.Responding } 接下来,这个进程对象将将告诉你这个进程是否有反应:
PS> Test-ServiceResponding -ServiceName Spooler True
注意这个例子代码中假设它的服务是运行的,如果需要,你也可以检查下服务有没有运行。
本方法适合所有的powershell版本
您可能感兴趣的文章:
相关内容
- Powershell小技巧之系统运行时间_PowerShell_
- Windows Powershell 执行文件和脚本_PowerShell_
- Windows Powershell 通过函数扩展别名_PowerShell_
- Windows Powershell 别名_PowerShell_
- Powershell小技巧之编辑Hosts文件_PowerShell_
- Powershell小技巧之记录脚本的操作_PowerShell_
- Powershell小技巧之获取MAC地址_PowerShell_
- Windows Powershell Do While 循环_PowerShell_
- Windows Powershell Foreach 循环_PowerShell_
- Windows Powershell ForEach-Object 循环_PowerShell_
