Need to convert a .bat file to .ps1

Kurtz, Philip 1 Reputation point
2021-05-20T16:20:29.693+00:00

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 for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 36,291 Reputation points
    2021-05-20T21:55:25.287+00:00

    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
    }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.