question

KurtzPhilip-2163 avatar image
0 Votes"
KurtzPhilip-2163 asked MotoX80 answered

Need to convert a .bat file to .ps1

we have a bat file that runs a command that is now on another server

looking to convert this into .ps1:

"\\00.111.222.33\C$\mydir\dir" /job:runmyjob /location:"\\00.111.333..44\c$\otherdir\dir"


Thanks

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MotoX80 avatar image
0 Votes"
MotoX80 answered

There is really nothing to convert. A .bat file as well as a Powershell .PS1 script can execute a program.

 C:\Windows\System32\whoami.exe /groups 

That statement is valid in both .bat and .ps1.

If the program that you want to execute is stored on another machine then just point the .bat/.ps1 to it.



 \\00.111.222.33\C$\mydir\dir\MyProgram.exe /job:runmyjob

Since you've referenced C$, the account that executes the script will need to have administrator access on the 00.111.222.33 machine.

The machine that you run the script on will copy the MyProgram.exe over the network and load and execute it on the local machine where the script is running.

If you want to have a script on one machine launch a program on another machine then you need to use invoke-command.

 Invoke-Command -ComputerName 00.111.222.33 -ScriptBlock {
     C:\mydir\dir\MyProgram.exe /job:runmyjob
 }




5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.