powershell - how to get a pc list that have a service running on each pc? -
i m using psexec auto run cmd on pcs on our network check if process running or not. wannt list pc name has service running on. how can powershell?
this m running now. 2 batch files , 1 text file.
get.bat
tasklist | findstr pmill.exe >> dc-01\c$\0001.txt
run_get.bat
psexec @%1 -u administrator -p password -c "c:\get.bat"
pclist.txt
what got in result pmill.exe , m wondering if there anyway can output pc name has pmill.exe running on?
hint plz!
if computers have powershell installed remoting enabled, can seek script below. outputs computers not reachable can retest them later if want to. if don't need it, remove content within catch
-block(or of try/catch
):
$out = @() get-content "pclist.txt" | foreach { $pc = $_ seek { if((get-process -name "pmill" -computername $pc) -ne $null) { $out += $_ } } grab { #unknown error $out += "error: $pc not checked. $_.message" } } $out | set-content "out.txt"
pclist.txt:
graimer-pc pcwithoutprocesscalledpmill testcomputer testpc graimer-pc
out.txt (log):
graimer-pc error: testcomputer unreachable error: testpc unreachable graimer-pc
powershell batch-file powershell-v2.0
No comments:
Post a Comment