APM_PowerShell TrustedHosts作用(用法)

APM_PowerShell TrustedHosts作用(用法)

当我们需要在AppManager中添加PowerShell监控时,我们需要将对应的APM设备添加到TrustedHosts中,否则无法执行PowerShell脚本。

并且TrustedHosts可以限制在设备上执行脚本的主机。

查看TrustedHosts列表的计算机:

Get-Item WSMan:\localhost\Client\TrustedHosts

将所有的计算机添加到TrustedHosts列表:

Set-Item WSMan:\localhost\Client\TrustedHosts -Value *

将特定计算机添加到 TrustedHosts 列表:

您可以使用以下命令添加基于主机名选择的特定计算机,方法是用逗号 (,) 分隔它们,其中 ComputerName 可以采用 Server01 或 Server01.yourdomain.com 格式。

Set-Item WSMan:\localhost\Client\TrustedHosts -Value <ComputerName>,[<ComputerName>]

将计算机添加到 TrustedHosts 的现有列表:

如果已将某些计算机添加到 TrustedHosts 列表中,并且想要添加其他计算机,而不删除以前的条目,则应使用以下方法。这是因为 TrustedHosts 列表会根据您运行的最后一个 Set-Item 命令进行更新,从而覆盖以前的条目。

使用以下命令将当前 TrustedHosts 计算机列表保存到 curList 变量。

$curList = (Get-Item WSMan:\localhost\Client\TrustedHosts).value

若要将计算机添加到当前列表,请通过指定您创建的变量和要添加的计算机名称来键入以下命令。

Set-Item WSMan:\localhost\Client\TrustedHosts -Value "$curList, Server01"

或者,若要避免使用变量,请将 -Concatenate 开关添加到 Set-Item 命令中,以添加新条目和以前的条目。例如:

Set-Item WSMan:\localhost\Client\TrustedHosts -Concatenate -Value Server02

使用 IP 地址将计算机添加到 TrustedHosts 列表:

与前面的命令类似,您可以使用 IPv4 或 IPv6 地址。对于 IPv6,您必须键入 [] 之间的地址。

Set-Item WSMan:\localhost\Client\TrustedHosts -Value 10.10.10.1,[0:0:0:0:0:0:0:0]