none
Remote program execution for multiple servers RRS feed

  • Question

  • Hello,

    I am trying to copy a file and execute on numerous servers remotely. the file copies successfully but unfortunately the exe doesn't executes. Can someone please identify where it goes wrong. below is script

    #Variables

    $computername = Get-Content servers2.txt

    $sourcefile = "C:\Users\username1\Downloads\app\folder2\app.exe"

    $destinationFolder = "\\$computer\C$\admin\scripts"

    #This section will install the software

    foreach ($computer in $computername)

    {

            #It will copy $sourcefile to the $destinationfolder. If the Folder does not exist it will create it.

     

        if (!(Test-Path -path $destinationFolder))

        {

            New-Item $destinationFolder -Type Directory

        }

        Copy-Item -Path $sourcefile -Destination $destinationFolder}

        Invoke-Command -ComputerName $computer -ScriptBlock {Start-Process "C:\Admin\Scripts\app.exe"}

    Thank you,

     


    MYM

    Tuesday, February 19, 2019 8:11 AM

Answers

  • Try this:

    Invoke-Command -ScriptBlock

    {Start-Process"C:\Admin\Scripts\app.exe" -Wait-ComputerName $computer

    Tuesday, February 19, 2019 8:53 AM

All replies

  • Try this:

    Invoke-Command -ScriptBlock

    {Start-Process"C:\Admin\Scripts\app.exe" -Wait-ComputerName $computer

    Tuesday, February 19, 2019 8:53 AM
  • Thanks for quick reply Pedro.

    Will try it now and let you know

    Thank you so much.


    MYM

    Tuesday, February 19, 2019 8:55 AM
  • You cannot remotely launch most exe files.  It cannot work with GUI apps.  Also the invoke session will terminate and any thing executing will be terminated.

    If the app is a command utility then the Start-Process -wait will work most of the time. Some apps like RoboCopy will not behave correctly.


    \_(ツ)_/

    Tuesday, February 19, 2019 9:13 AM
  • Hi jrv,

    This application can be run from cmd aswell. Can you please guide on how to achieve this?

    Thank you :)


    MYM

    Tuesday, February 19, 2019 9:17 AM
  • I just remembered that my example worked with .msi files, with .exe i do not probe it.

    To .exe files i use Psexec

    • Edited by Pedro_A Tuesday, February 19, 2019 9:28 AM
    Tuesday, February 19, 2019 9:25 AM
  • It does gets copied but never gets executed. may be i can call cmd remotely and execute the program through cmd..

    MYM

    Tuesday, February 19, 2019 9:30 AM
  • You have to use Start-Process with wait.  May programs cannot be run remotely.  We cannot help you without knowing the program.


    \_(ツ)_/

    Tuesday, February 19, 2019 9:32 AM
  • that's  a custom program and runs from within cmd aswell. Scans files and quits after done and generates a log file within same folder

    MYM

    Tuesday, February 19, 2019 9:34 AM
  • What does "runs from within cmd aswell" mean?  As I posted, some commands cannot run correctly in a remote session.

    How do you know it doesn't work?  What are the errors?  Have you contacted the vendor to find out if there are issues with the program?


    \_(ツ)_/

    Tuesday, February 19, 2019 12:28 PM