I've been working on trying to run a Powershell script on the network using PSExec, but every time I run it, I get this message:
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.
The goal of the script is to traverse domain-connected laptops and save a specific list of directories to a file on my computer. That script is as follows:
powershell.exe -command "& {& get-childitem 'c:\users\*\appdata\local\google\chrome\user*data\default\extensions\*'}" > \\[MY_COMPUTER]\C$\users\[USERNAME]\desktop\Chrome_Extensions.txt
I am calling this script with this command:
psexec \\[COMPUTER] /s cmd /c %SystemRoot%\system32\WindowsPowerShell\
v1.0\powershell.exe -ExecutionPolicy Bypass -file c:\apps\test.ps1
When I run the script without psexec \\[COMPUTER] /s
, it runs fine and saves the correct information about the computer I'm running it on, then sends the information to my computer's desktop. But running it with the aforementioned line causes the error above, and I can't target machines on the network. So, what about the PSExec command causes this to error out, as it doesn't seem like there's really a lot to it? Perhaps I'm misunderstanding, and assuming that PSExec should run the same as PowerShell, which very well might not be the case. I guess I'm just a little lost on how to use it, and any assistance would be greatly appreciated! Thank you!