在多台远程机器上获取服务 [英] Get-Service on multiple remote machines

查看:35
本文介绍了在多台远程机器上获取服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只能获取在文本文件中返回第一台计算机上的服务的命令.有没有比 for-each 更好的方法来完成这项任务?

I can only get the command to return the services on the first computer in the text file. Is there a better way than for-each for this task?

Get-Service *vault* -ComputerName (Get-Content c:\users\sean\desktop\js.txt) | select name,status,machinename | sort machinename | format-table -autosize

推荐答案

尝试不使用 get-content.试试这个:

Try it without the get-content. Try this:

Get-Service *vault* -ComputerName c:\users\sean\desktop\js.txt | select name,status,machinename | sort machinename | format-table -autosize

如果这不起作用,请尝试:

If that doesn't work, then try:

$Computers = Get-Content c:\users\sean\desktop\js.txt
Get-Service *vault* -computername $Computers | Select name,status,machinename |sort machinename |format-table -autosize

如果你渴望单线,那么试试这个:

If you are eager for a one-liner then try this:

Get-Content c:\users\sean\desktop\js.txt | Get-Service *vault* | Select name,status,machinename |sort machinename |format-table -autosize

我会先尝试最上面的.我会进行测试,但我现在无法访问任何可以进行适当测试的内容.

I would try the top one first. I would test, but I don't have access to anything I can do a proper test right now.

这篇关于在多台远程机器上获取服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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