如何让那些在每台PC上运行的服务的PC列表? [英] how to get a pc list that have a service running on each pc?

查看:364
本文介绍了如何让那些在每台PC上运行的服务的PC列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我米使用PSEXEC自动运行CMD,从我们的网络上的所有计算机来检查,如果某些进程正在运行与否。但我wannt与具有服务上运行的所有计算机名称的列表。我怎么能做到这一点从PowerShell的?

I m using psexec to auto run from cmd on all PCs on our network to check if certain process is running or not. but i wannt a list with all pc name that has the service running on. how can i do it from powershell?

这是我男运行。 2批处理文件和1个文本文件。

this is what i m running now. 2 batch files and 1 text file.

get.bat

任务列表| FINDSTR pmill.exe >> DC-01 \\ C $ \\ 0001.txt

tasklist | findstr pmill.exe >> dc-01\c$\0001.txt

run_get.bat

run_get.bat

PSEXEC @%1 -u管理员密码-p -cC:\\ get.bat

psexec @%1 -u administrator -p password -c "C:\get.bat"

pclist.txt

pclist.txt

我从该得到的结果只是所有pmill.exe,I M想知道是否有反正我可以输出已pmill.exe运行在PC上的名字吗?

what i got from this in result are just all pmill.exe , i m wondering if there is anyway that i can output the PC name that has pmill.exe running on?

提示PLZ!

推荐答案

,你可以试试下面的脚本。它还输出那些不可达的,所以你可以,如果你想在以后重新测试他们的计算机。如果你不需要它,只是删除抓里面的内容 - 块(或全部中的try / catch ):

If all computers have powershell installed with remoting enabled, you can try the script below. It also outputs computers that were not reachable so you can retest them later if you want to. If you don't need it, just remove the content inside the catch-block(or all of try/catch):

$out = @()
Get-Content "pclist.txt" | foreach {
    $pc = $_ 
    try {
        if((Get-Process -Name "pmill" -ComputerName $pc) -ne $null) {
            $out += $_
        }
    } catch { 
        #Unknown error
        $out += "ERROR: $pc was not checked. $_.Message"
    }
}

$out | Set-Content "out.txt"

pclist.txt:

pclist.txt:

graimer-pc
pcwithoutprocesscalledpmill
testcomputer
testpc
graimer-pc

Out.txt(日志):

Out.txt (log):

graimer-pc
ERROR: testcomputer is unreachable
ERROR: testpc is unreachable
graimer-pc

这篇关于如何让那些在每台PC上运行的服务的PC列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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