Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6215
  • Last Modified:

Execute a PowerShell script on a remote machine with PSExec

Hello. I have a PowerShell script on several remote machines that I would like to execute with PSExec (Windows Remote Management is not an option). The script is on the E: drive. When I run the below command from my machine, I get this error Processing -file 'e:\copy.ps1' failed because the file does not have a '.ps1' extension. Specify a valid PowerShell script file name, and then try again.

psexec \\server1 cmd /c "echo . | powershell -file e:\copy.psl"

What am I missing?
0
Lorrec
Asked:
Lorrec
  • 2
1 Solution
 
Chris DentPowerShell DeveloperCommented:
It took a moment or two to see this, but you named your file e:\copy.PSL (upper-case because lower really doesn't help show this).

It needs to be PS1 (numeric 1).

Chris
0
 
LorrecAuthor Commented:
Wow. I feel stupid and must be losing it. Not sure how I missed that. Thank you for the quick response.
0
 
LorrecAuthor Commented:
Thank you
0
 
pcelbaCommented:
Fantastic!  I mean the  echo.  I've been investigating long minutes how to force powershell to exit on remote machine.

Thanks!
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now