1 Reply Latest reply on Oct 20, 2016 11:48 AM by Bill Robinson

    Redirect the output of multiple powershell commands (using nexec) into single file

    Yogeesh Kompa

      Dear All,

       

      I am trying to run the below powershell command.

       

      nexec targetserver cmd -e /c "powershell.exe -executionpolicy bypass -command "Command1 ; Command2""

       

      The command executes without any problem and gives the desired output.

       

      Now my requirement is to redirect the output of Command1 and Command2 in the same outputfile which is supposed be hosted on BSA server (Source server from where I am executing powershell command) and after execution it should prompt out (not happening now).

       

      I have tried to redirect in the end i.e. nexec targetserver cmd -e /c "powershell.exe -executionpolicy bypass -command "Command1 ; Command2"" > //BSAServer/C/output.txt and it threw

      error "The network name cannot be found" and if I change to local i.e.  > //targetserver/C/output.txt then also it threw same error.

       

      Please help.

       

      Regards,

      Yogeesh

        • 1. Re: Redirect the output of multiple powershell commands (using nexec) into single file
          Bill Robinson

          escape the ; and you have a -e in the wrong place i think.

           

          nexec 192.168.52.129 cmd /c "powershell -executionpolicy bypass -inputformat NONE -command "get-childitem -path env:computername \; get-childitem -path env:computername"" > //blapp88-1.local/tmp/foo

          prime% cat //blapp88-1.local/tmp/foo

           

          Name                           Value                                          

          ----                           -----                                          

          COMPUTERNAME                   BLAPP                                          

          COMPUTERNAME                   BLAPP        

          2 of 2 people found this helpful