Need to run Powershell script which placed on different server RRS feed

  • Question

  • Hello,

    I want to call powershell script from Server A, Where script is placed in server B.

    Anyway should be fine from batch file or any script..

    Please suggest.

    Thank You,


    Monday, July 1, 2019 1:41 PM

All replies

  • Please read this first:  This forum is for scripting questions rather than script requests.

    Also find scripts here:  PowerShell Gallery or here:  TechNet Gallery - resources for IT professionals.

    Learn PowerShell:  Microsoft Channel 9 - Getting Started with Microsoft PowerShell 3.0.

    Script requests: Microsoft Technet Script Center - Requests.

    If you want to run a Powershell script from another Powershell script you simply call it with a relative or with  it's complete path (UNC path in you case).

    Live long and prosper!


    • Proposed as answer by jrv Tuesday, July 2, 2019 2:37 AM
    Monday, July 1, 2019 2:08 PM
  • If the server B path is accessible from server A you can directly use the full path to run the script using powershell, e.g.


    • Proposed as answer by jrv Tuesday, July 2, 2019 2:37 AM
    Monday, July 1, 2019 4:23 PM
  • Hello Avis,

    On Server B, you should open PowerShell as Administrator. Then run the command "Enable-PSRemoting -Force". This will allow server B to have PowerShell commands executed remotely.

    To be able to run PowerShell commands on server A and server B, you might need to set the execution policy first. This is done With the "Set-ExecutionPolicy" command.

    On Server A, run the command "Invoke-Command -ComputerName IpAddress/NameOfComputer -ScriptBlock { C:\Path\To\Script.ps1 } -credential UsernameOfAccountExecutingTheCommand"

    I am not the best at PowerShell, and i have not tested this, but i hope it Works for you.



    Tuesday, July 2, 2019 1:39 AM
  • Hi Frank,

    Invoke-command: Runs commands on local and remote computers.


    Your script example is to use the powershell command to run a script on server B remotely from server A to server B. The script is still only run on server B, you just get the output of the script on server A (if the script If there is an output result).

    But I think OP wants to run the server B's powershell script on server A.

    You can try to use "-filepath" parameter.

    -filepath: Specifies a local script that this cmdlet runs on one or more remote computers. Enter the path and file name of the script, or pipe a script path to Invoke-Command. The script must reside on the local computer or in a directory that the local computer can access. Use ArgumentList to specify the values of parameters in the script.

    For example:

    Invoke-Command -FilePath c:\scripts\test.ps1 -ComputerName Server01
    This command runs the Test.ps1 script on the Server01 computer.
    The command uses the FilePath parameter to specify a script that is located on the local computer. The script runs on the remote computer and the results are returned to the local computer.

    Best regards,


    Just do it.

    Tuesday, July 2, 2019 2:07 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,


    Just do it.

    Wednesday, July 31, 2019 8:40 AM