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
Last updated
Was this helpful?