PsExec引发错误消息,但没有任何问题

Sim*_*s0n 10 windows powershell automation psexec

因此,我们在自动化中使用PsExec来安装虚拟机,因为我们无法在Windows 2003机器上使用ps远程会话.一切都很好,并没有问题,但PsExec不断抛出错误,即使每个命令都没有正确执行.例如:

D:\tools\pstools\psexec.exe $guestIP -u $global:default_user -p $global:default_pwd -d -i C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command "Enable-PSRemoting -Force"
Run Code Online (Sandbox Code Playgroud)

在guest虚拟机上启用PsRemoting,但也会抛出此错误消息:

psexec.exe : 
Bei D:\Scripts\VMware\VMware_Module5.ps1:489 Zeichen:29
+     D:\tools\pstools\psexec.exe <<<<  $guestIP -u $global:default_user -p $global:default_pwd -d -i C:\Windows\System32\WindowsPowerShell\
v1.0\powershell.exe -command "Enable-PSRemoting -Force"
+ CategoryInfo          : NotSpecified: (:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError

PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com


Connecting to 172.17.23.95...Starting PsExec service on 172.17.23.95...Connecting with PsExec service on 172.17.23.95...Starting C:\Windows\
System32\WindowsPowerShell\v1.0\powershell.exe on 172.17.23.95...
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe started on 172.17.23.95 with process ID 2600.
Run Code Online (Sandbox Code Playgroud)

无论我如何使用psexec,如引号,vriables /固定值,其他标志等,这些类型的错误消息始终如一.是否有人知道如何解决这个问题?这不是一个真正的问题,但它会让发现错误成为一种痛苦,因为"错误"无处不在.完全禁用psexec的错误消息也会有所帮助......

Tes*_*ler 14

这是因为当进程写入STDERR时,PowerShell有时会报告NativeCommandError.PsExec写入infoline

PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com
Run Code Online (Sandbox Code Playgroud)

到STDERR这意味着它可以导致这种情况.

有关更多信息,请参阅以下问题/答案:


Gop*_*lai 5

将 stderr 重定向到 null 对我来说效果最好。请参阅下面的链接

使用 IDE 时从 Powershell 调用第 3 方可执行文件时出错

这是该链接的相关部分:

为了避免这种情况,你可以将 stderr 重定向到 null,例如:

du 2> $null 本质上,控制台主机和 ISE(以及远程)以不同方式对待 stderr 流。在控制台主机上,PowerShell 支持 edit.com 等应用程序与其他将彩色输出和错误写入屏幕的应用程序一起工作非常重要。如果 I/O 流未在控制台主机上重定向,PowerShell 将为本机 EXE 提供一个控制台句柄以直接写入。这会绕过 PowerShell,因此 PowerShell 无法看到写入的错误,因此它无法通过 $error 或写入 PowerShell 的 stderr 流来报告错误。ISE 和远程处理不需要支持这种情况,因此它们确实会在 stderr 上看到错误,然后写入错误并更新 $error。

.\PsExec.exe \$主机名 -u $script:用户名 -p $script:密码 /accepteula -h cmd /c $powerShellArgs 2> $null


归档时间:

查看次数:

15918 次

最近记录:

8 年,7 月 前