将多个主机添加到可信主机列表 [英] Adding multiple hosts to trusted hosts list
问题描述
Hii,
我正在尝试从文本文件中读取服务器列表,并使用foreach循环将它们添加到可信主机。
I am trying to read a list of servers from text file and addinn them to trusted hosts using foreach loop.
但是得到的错误为:
语法错误:输入必须是{KEY =" VALUE" [; KEY =" VALUE"]}}的形式$ b
Syntax Error: input must be of the form {KEY="VALUE"[;KEY="VALUE"]}
,代码为: -
#$ cred = get-credential
foreach(Get-Content -path D中的$服务器:\ servers.txt)
{
winrm s winrm / config / client'@ {TrustedHosts =" $ servers"}'¥b $ b $
}
#$cred = get-credential
foreach ($servers in Get-Content -path D:\servers.txt)
{
winrm s winrm/config/client '@{TrustedHosts="$servers"}'
}
提前致谢! !
推荐答案
不确定是什么您的servers.txt内容看起来像,但您应该将您的Get-Content cmdlet放在()中,以便在foreach尝试处理部分循环之前对其进行处理并检索内容。
not sure what you servers.txt content looks like but you should put your Get-Content cmdlet in () so it is processed and the content is retrieved before foreach tries to process the in part of the loop.
foreach(
服务器(Get-Content -path D:\ servers.txt))
servers in (Get-Content -path D:\servers.txt))
这篇关于将多个主机添加到可信主机列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!