none
How to Invoke powershell script that relies on additional scripts to a remote computer RRS feed

  • Question

  • Invoke-Command -Computername testVM -filepath C:\removeoffice\Remove-PreviousOfficeInstalls.ps1

    This executes on a remote computer fine- problem is that this script pulls another script located in the same directory. Is it possible to invoke the command to the remote computer so that it can also run the additional scripts?

    • Moved by Bill_Stewart Wednesday, November 29, 2017 6:41 PM This is not "scripts on demand"
    Wednesday, October 18, 2017 5:09 PM

All replies

  • Combine the two into a single file.

    \_(ツ)_/

    Wednesday, October 18, 2017 5:18 PM
  • Is it possible to invoke without combining the scripts?
    Wednesday, October 18, 2017 6:00 PM
  • If the scripts are designed correctly we can do this:

    $session = New-PSSession -ComputerName somepc
    invoke-command -FilePath file1.ps1 -Session $session
    invoke-command -FilePath file2.ps1 -Session $session
    Remove-PSSession $session
    

    Now they will run in order in the same session.


    \_(ツ)_/

    Wednesday, October 18, 2017 6:11 PM