Running batch file on remote machine (VM) using PowerShell











up vote
0
down vote

favorite












Quick question, have searched for awhile but can't find answer anywhere.
Some background:
I have a local machine and remote machine (Virtual Machine) that I am connecting through RDP.



I have a batch file that I run that starts the RDP session through powershell commands and logs in with credentials.
My next step is where I run into problems, I have another batch file on the remote machine that I want to run (also Powershell commands).



When I run this batch file physically through the RDP (by either double clicking or running through command prompt) all is well.



When I trigger the batch file remotely the batch file runs, but not the way I want. It seems like it runs in the background and not actually showing what its doing through the RDP session I have. The reason I don't want this running in silent mode is because I have a script that uninstalls and re installs a program. Since it is not MSI I have to have several "Send Keys" in my code.



So in the end my question is this, can I run a batch file remotely that will act as if I double clicked the batch file on the remote machine??? I believe that there is an option psexec, but I would prefer not to use any more programs than needed.










share|improve this question






















  • ok seems like this is a limitation of powershell and not of the batch file im running. The ps1 files allow for a non-interactive session to be created. Anyone have a workaround?
    – kal
    Jan 14 '15 at 22:18










  • Did you manage to solve this yet? I have just come across the same issue and trying to find a fix. My batch file triggers a load of python scripts and doesn't work if i trigger it remotely but it did correctly if i RDP manually and double click the batch file.
    – Will Webb
    May 18 '16 at 15:32















up vote
0
down vote

favorite












Quick question, have searched for awhile but can't find answer anywhere.
Some background:
I have a local machine and remote machine (Virtual Machine) that I am connecting through RDP.



I have a batch file that I run that starts the RDP session through powershell commands and logs in with credentials.
My next step is where I run into problems, I have another batch file on the remote machine that I want to run (also Powershell commands).



When I run this batch file physically through the RDP (by either double clicking or running through command prompt) all is well.



When I trigger the batch file remotely the batch file runs, but not the way I want. It seems like it runs in the background and not actually showing what its doing through the RDP session I have. The reason I don't want this running in silent mode is because I have a script that uninstalls and re installs a program. Since it is not MSI I have to have several "Send Keys" in my code.



So in the end my question is this, can I run a batch file remotely that will act as if I double clicked the batch file on the remote machine??? I believe that there is an option psexec, but I would prefer not to use any more programs than needed.










share|improve this question






















  • ok seems like this is a limitation of powershell and not of the batch file im running. The ps1 files allow for a non-interactive session to be created. Anyone have a workaround?
    – kal
    Jan 14 '15 at 22:18










  • Did you manage to solve this yet? I have just come across the same issue and trying to find a fix. My batch file triggers a load of python scripts and doesn't work if i trigger it remotely but it did correctly if i RDP manually and double click the batch file.
    – Will Webb
    May 18 '16 at 15:32













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Quick question, have searched for awhile but can't find answer anywhere.
Some background:
I have a local machine and remote machine (Virtual Machine) that I am connecting through RDP.



I have a batch file that I run that starts the RDP session through powershell commands and logs in with credentials.
My next step is where I run into problems, I have another batch file on the remote machine that I want to run (also Powershell commands).



When I run this batch file physically through the RDP (by either double clicking or running through command prompt) all is well.



When I trigger the batch file remotely the batch file runs, but not the way I want. It seems like it runs in the background and not actually showing what its doing through the RDP session I have. The reason I don't want this running in silent mode is because I have a script that uninstalls and re installs a program. Since it is not MSI I have to have several "Send Keys" in my code.



So in the end my question is this, can I run a batch file remotely that will act as if I double clicked the batch file on the remote machine??? I believe that there is an option psexec, but I would prefer not to use any more programs than needed.










share|improve this question













Quick question, have searched for awhile but can't find answer anywhere.
Some background:
I have a local machine and remote machine (Virtual Machine) that I am connecting through RDP.



I have a batch file that I run that starts the RDP session through powershell commands and logs in with credentials.
My next step is where I run into problems, I have another batch file on the remote machine that I want to run (also Powershell commands).



When I run this batch file physically through the RDP (by either double clicking or running through command prompt) all is well.



When I trigger the batch file remotely the batch file runs, but not the way I want. It seems like it runs in the background and not actually showing what its doing through the RDP session I have. The reason I don't want this running in silent mode is because I have a script that uninstalls and re installs a program. Since it is not MSI I have to have several "Send Keys" in my code.



So in the end my question is this, can I run a batch file remotely that will act as if I double clicked the batch file on the remote machine??? I believe that there is an option psexec, but I would prefer not to use any more programs than needed.







windows remote-desktop batch powershell






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 14 '15 at 20:18









kal

111




111












  • ok seems like this is a limitation of powershell and not of the batch file im running. The ps1 files allow for a non-interactive session to be created. Anyone have a workaround?
    – kal
    Jan 14 '15 at 22:18










  • Did you manage to solve this yet? I have just come across the same issue and trying to find a fix. My batch file triggers a load of python scripts and doesn't work if i trigger it remotely but it did correctly if i RDP manually and double click the batch file.
    – Will Webb
    May 18 '16 at 15:32


















  • ok seems like this is a limitation of powershell and not of the batch file im running. The ps1 files allow for a non-interactive session to be created. Anyone have a workaround?
    – kal
    Jan 14 '15 at 22:18










  • Did you manage to solve this yet? I have just come across the same issue and trying to find a fix. My batch file triggers a load of python scripts and doesn't work if i trigger it remotely but it did correctly if i RDP manually and double click the batch file.
    – Will Webb
    May 18 '16 at 15:32
















ok seems like this is a limitation of powershell and not of the batch file im running. The ps1 files allow for a non-interactive session to be created. Anyone have a workaround?
– kal
Jan 14 '15 at 22:18




ok seems like this is a limitation of powershell and not of the batch file im running. The ps1 files allow for a non-interactive session to be created. Anyone have a workaround?
– kal
Jan 14 '15 at 22:18












Did you manage to solve this yet? I have just come across the same issue and trying to find a fix. My batch file triggers a load of python scripts and doesn't work if i trigger it remotely but it did correctly if i RDP manually and double click the batch file.
– Will Webb
May 18 '16 at 15:32




Did you manage to solve this yet? I have just come across the same issue and trying to find a fix. My batch file triggers a load of python scripts and doesn't work if i trigger it remotely but it did correctly if i RDP manually and double click the batch file.
– Will Webb
May 18 '16 at 15:32










1 Answer
1






active

oldest

votes

















up vote
0
down vote













Have you tried Enter-PSSession?



$s = New-PSSession -ComputerName Server01 -Credential Domain01User01 
# Enter the session yourself
Enter-PSSession -Session $s


or



Invoke-Command -Session $s -ScriptBlock {
[SCRIPT GOES HERE]
}





share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f864812%2frunning-batch-file-on-remote-machine-vm-using-powershell%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    Have you tried Enter-PSSession?



    $s = New-PSSession -ComputerName Server01 -Credential Domain01User01 
    # Enter the session yourself
    Enter-PSSession -Session $s


    or



    Invoke-Command -Session $s -ScriptBlock {
    [SCRIPT GOES HERE]
    }





    share|improve this answer

























      up vote
      0
      down vote













      Have you tried Enter-PSSession?



      $s = New-PSSession -ComputerName Server01 -Credential Domain01User01 
      # Enter the session yourself
      Enter-PSSession -Session $s


      or



      Invoke-Command -Session $s -ScriptBlock {
      [SCRIPT GOES HERE]
      }





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        Have you tried Enter-PSSession?



        $s = New-PSSession -ComputerName Server01 -Credential Domain01User01 
        # Enter the session yourself
        Enter-PSSession -Session $s


        or



        Invoke-Command -Session $s -ScriptBlock {
        [SCRIPT GOES HERE]
        }





        share|improve this answer












        Have you tried Enter-PSSession?



        $s = New-PSSession -ComputerName Server01 -Credential Domain01User01 
        # Enter the session yourself
        Enter-PSSession -Session $s


        or



        Invoke-Command -Session $s -ScriptBlock {
        [SCRIPT GOES HERE]
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 23 '15 at 19:13









        user317619

        212




        212






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f864812%2frunning-batch-file-on-remote-machine-vm-using-powershell%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

            Mangá

            Eduardo VII do Reino Unido