powershell-remoting - 为远程服务器运行 WinRM quickconfig
问题描述
我正在编写一个 PowerShell 脚本,它从文件中读取主机列表。我尝试了两种不同的方法,两者都有问题。
第一种方法:
$WinRM = Invoke-Command -Computer $server -ScriptBlock { WinRM quickconfig }
这会在某些主机上显示以下错误消息:
WSManFault + CategoryInfo : NotSpecified: (WSManFault:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError + PSComputerName:svclebetapool01.lehi.micron.com 消息 = 访问被拒绝。 错误号:-2147024891 0x80070005 访问被拒绝。
第二种方法:
$WinRM = C:\PSTools\PsExec.exe \\$server -s winrm.cmd quickconfig -q
这设置$WinRM
为退出代码(成功执行时为 1)。>
如果我用or重定向输出>>
,那么它会显示 PsExec 版权。我正在寻找由WinRM quickconfig
命令创建的确切消息,以便我知道如何在不同情况下处理它。
解决方案
if your intention is to enable PowerShell remoting, then you can
C:\PSTools\PsExec.exe \\$server PowerShell.exe -c "Enable-PSRemoting -Force"
or
wmic /node:$Server process call create "PowerShell.exe -c 'Enable-PSRemoting -Force'"
推荐阅读
- python - 自动增量字段的问题
- java - 找不到 org.geoserver:gs-wms:jar:2.5.2
- javascript - 使用 else if 语句重构组件
- mongodb - 合并不同集合的两个对象并在Mongodb中获取特定数据
- python - Spacy 标记器损失在训练时为零
- ruby-on-rails - 在rails中导入excel文件时如何在模型中传递参考ID
- javascript - 尽管元素存在,但量角器并未等待页面加载
- c# - 将类对象的可观察集合绑定到 ListBox 和 UserControl (WPF)
- sql - 使用局部变量在 SQL 中设置表字段
- c++ - 使用线程类在 C++ 中构造动态线程数组时出错