如何使用winrm将多台计算机添加到可信主机列表中

 早安丶晚安丶英语连_691 发布于 2023-01-29 15:10

要从远程计算机在计算机上运行powershell命令,我们必须将远程计算机添加到主机的可信主机列表中.

我使用以下命令将机器A添加到机器B的可信主机:

winrm set winrm/config/client ‘@{TrustedHosts="machineA"}’

如何添加更多机器说机器C,机器D到机器B的可信主机列表?

3 个回答
  • LoïcMICHEL建议的答案盲目地将一个新值写入TrustedHosts条目.
    我相信,更好的方法是首先查询TrustedHosts.
    正如Jeffery Hicks在2010年发布的那样,首先查询TrustedHosts条目:

    PS C:\> $current=(get-item WSMan:\localhost\Client\TrustedHosts).value
    PS C:\> $current+=",testdsk23,alpha123"
    PS C:\> set-item WSMan:\localhost\Client\TrustedHosts –value $current
    

    2023-01-29 15:13 回答
  • winrm set winrm/config/client '@{TrustedHosts="machineA,machineB"}'
    

    2023-01-29 15:13 回答
  • 我更喜欢与PSDrive合作WSMan:\.

    获取TrustedHosts

    Get-Item WSMan:\localhost\Client\TrustedHosts
    

    设置TrustedHosts

    提供单个逗号分隔的计算机名称字符串

    Set-Item WSMan:\localhost\Client\TrustedHosts -Value 'machineA,machineB'
    

    或者(危险的)外卡

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

    要附加到列表,-Concatenate可以使用该参数

    Set-Item WSMan:\localhost\Client\TrustedHosts -Value 'machineC' -Concatenate
    

    2023-01-29 15:13 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有