> For the complete documentation index, see [llms.txt](https://jen-hsuan-hsieh.gitbook.io/powershell-programming-and-relative-experience/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jen-hsuan-hsieh.gitbook.io/powershell-programming-and-relative-experience/chapter2_remote_controlling_by_windows_powershell/25run-remote-program.md).

# 2.5.Run remote program

* 1.Run powershell script:
  * 1.use start-process

    ```
         $passwd = convertto-securestring -AsPlainText -Force -String $clientPassword
         $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $clientUser,$passwd
         $session = new-pssession -computername $clientIP -credential $cred
         Invoke-Command -Session $session -ScriptBlock {param($clientDrive, $clientShareFolder) Start-Process powershell.exe -ArgumentList "$clientDrive\$clientShareFolderfbwfDisableSetting.ps1" $clientDrive $clientShareFolder}  -Args $clientDrive, $clientShareFolder
    ```
  * 2.Not use start-process
    * In some condition, it will cause computer to hang on when remote using "start-process", so do not use start-process, for example:

      ```
       $passwd = convertto-securestring -AsPlainText -Force -String $clientPassword
       $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $clientUser,$passwd
       $session = new-pssession -computername $clientIP -credential $cred
       Invoke-Command -Session $session -ScriptBlock {param($clientDrive, $clientShareFolder) cd "$clientDrive\$clientShareFolder"}  -Args $clientDrive, $clientShareFolder
       Invoke-Command -Session $session -ScriptBlock {.\fbwfDisableSetting.ps1 $clientDrive $clientShareFolder}  
      ```
* 2.Run .exe:
  * ex:

    ```
     bat2 ="RunOnce.exe"
     $executeFile2 = "$clientDrive\$clientShareFolder\$bat2"
     $arguments="noticestart $clientDrive\$clientShareFolder\psrmenable.bat"
     Invoke-Command -Session $session -ScriptBlock {param($executeFile2,$arguments) Start-Process -FilePath 
    ```
