PSExec:[计算机]上的cmd退出,错误代码为-196608

问题描述

我一直在尝试使用PSExec在网络上运行Powershell脚本,但是每次运行它时,都会收到以下消息:

PsExec v2.2 - Execute processes remotely
Copyright (C) 2001-2016 Mark Russinovich
Sysinternals - www.sysinternals.com

Couldn't access [COMPUTER]:
The filename,directory name,or volume label syntax is incorrect.

C:\PSTools> psexec \\[COMPUTER] /s cmd /c %SystemRoot%\system32\WindowsPowerShell\
v1.0\powershell.exe -ExecutionPolicy Bypass -file c:\apps\test.ps1

PsExec v2.2 - Execute processes remotely
Copyright (C) 2001-2016 Mark Russinovich
Sysinternals - www.sysinternals.com


The argument 'c:\apps\test.ps1' to the -File parameter does not exist. Provide
the path to an existing '.ps1' file as an argument to the -File parameter.
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

cmd exited on [COMPUTER] with error code -196608.

该脚本的目标是遍历与域连接的便携式计算机,并将目录的特定列表保存到计算机上的文件中。该脚本如下:

powershell.exe -command "& {& get-childitem 'c:\users\*\appdata\local\google\chrome\user*data\default\extensions\*'}" > \\[MY_COMPUTER]\C$\users\[USERNAME]\desktop\Chrome_Extensions.txt

我正在使用以下命令调用此脚本:

psexec \\[COMPUTER] /s cmd /c %SystemRoot%\system32\WindowsPowerShell\
v1.0\powershell.exe -ExecutionPolicy Bypass -file c:\apps\test.ps1

当我在不使用psexec \\[COMPUTER] /s 的情况下运行脚本时,它可以正常运行并保存有关正在运行的计算机的正确信息,然后将该信息发送到计算机的桌面。但是,使用上述行运行它会导致上述错误,并且我无法定位网络上的计算机。那么,关于PSExec命令,导致此错误的原因是什么呢,因为似乎没有太多的事情发生了?也许我误会了,并假设PSExec应该与PowerShell一样运行,但事实并非如此。我想我对如何使用它有点迷茫,对您的帮助将不胜感激!谢谢!

解决方法

在@Briantist的帮助下,我已经能够在目标计算机上运行命令Enable-PSRemoting,然后使用invoke-command -computername [COMPUTER] -filepath c:\apps\test.ps1运行脚本

使用PSExec太混乱了,所以我很高兴这能够以另一种方式工作。现在了解如何在域中的所有计算机上启用远程处理,而无需单独连接所有计算机并手动进行操作...

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...