首页 > 解决方案 > 为远程服务器运行 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命令创建的确切消息,以便我知道如何在不同情况下处理它。

标签: powershell-remotingpsexecinvoke-commandwinrm

解决方案


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'"

推荐阅读