【问题标题】:Get Service from remote machines in a domain从域中的远程机器获取服务
【发布时间】:2019-08-12 13:16:29
【问题描述】:

尝试获取域中具有特定服务的所有机器的列表

通过这里的所有帖子尝试过,每台机器都有帮助,但是如果我在多台机器上使用文本文件,它会失败

$computers = Get-Content c:\script\computers.txt
$service = "*crystal*"

foreach ($computer in $computers) {
$servicestatus = Get-Service -ComputerName $computer -Name $service

}

$Data = $servicestatus | Select-Object Name,Machinename | Format-Table -AutoSize

Write($Data) | Out-File c:\script\output.txt -Append

表中包含服务的机器的预期列表,但出现错误: 此操作可能需要其他权限

相同的脚本,但具有直接的机器名称,就像一个魅力。 有什么线索吗?

【问题讨论】:

  • 运行此脚本的用户帐户 - 它是远程计算机上的管理员吗?默认情况下,非管理员用户可以从服务控制管理器本地枚举服务,但不能远程枚举服务 - 您需要更新目标系统上的 scmanager sddl 或使用其他远程协议(WMI/CIM 或 WinRM)
  • 运行脚本的用户是域管理员,并且是所有远程目标上的本地管理员的一部分
  • sc.exe sdshow scmanager 对目标说了什么?
  • [1] 确切地 computers.txt 文件中有什么内容? [2] 正是错误文本是什么? [3]Write($Data)函数是什么? [4] 每次通过循环时,您都在 重置 $servicestatus
  • 大家好。最终让它工作。生病用使用的脚本编辑帖子。

标签: powershell powershell-2.0 powershell-remoting


【解决方案1】:

为什么不使用:

Invoke-Command -ComputerName $computers -ScriptBlock {Get-Service -Name *crystal*} 

最终,您可以将调用的结果存储到变量中并使用它。 使用 Insted foreach 的 Invoke-Command 的好处是 Invoke 是并行工作的,而 foreach 是串行的......

希望对你有帮助!

最好的问候,

伊万

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-03
    • 2018-04-24
    • 2013-05-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多