Yes, it's pretty straight forward:
$Session = New-PSSession -ComputerName "qtestwest01" $SB = { $pt = New-Object System.Diagnostics.ProcessStartInfo; $pt.FileName = "E:\testscripts\capture.bat"; $pt.UseShellExecute = $false; $pt.RedirectStandardInput = $true; $e = [System.Diagnostics.Process]::Start($pt); $e.StandardInput.WriteLine("`n") } Invoke-Command -Session $Session -ScriptBlock $SB
An aside: You may want to look at Start-Process -PassThru. Though I'm not sure you can set UseShellExecute using that pattern. There are some details about that here , but I didn't give it a thorough reading.
Update
Responding to your implementation and the parameter question, repeatedly calling Invoke-Command is unnecessary. You're calling into the same session so it's functionally the same thing, but everything you need is available so you can run a single command. The $Using: modifier can be used in a prefabricated ScriptBlock so long as the script block is used with certain cmdlets, including and maybe primarily Invoke-Command.
A new example:
$FilePath = "C:\windows\System32\notepad.exe" $Session = New-PSSession -ComputerName "Server1" $SB = { $pt = New-Object System.Diagnostics.ProcessStartInfo; $pt.FileName = $Using:FilePath; $pt.UseShellExecute = $false; $pt.RedirectStandardInput = $true; $e = [System.Diagnostics.Process]::Start($pt); $e.StandardInput.WriteLine("`n") } Invoke-Command -Session $Session -ScriptBlock $SB
A second method of passing parameters into a script block is to use the Invoke-Command -ArgumentList parameter:
Example:
$FilePath = "C:\windows\System32\notepad.exe" $Session = New-PSSession -ComputerName "Server1" $SB = { $pt = New-Object System.Diagnostics.ProcessStartInfo; $pt.FileName = $args[0] ; $pt.UseShellExecute = $false; $pt.RedirectStandardInput = $true; $e = [System.Diagnostics.Process]::Start($pt); $e.StandardInput.WriteLine("`n") } Invoke-Command -Session $Session -ScriptBlock $SB -ArgumentList $FilePath
And, Either approach, $Using or $args[0] will work even if cite the script block inline with the command:
Example:
$FilePath = "C:\windows\System32\notepad.exe" $Session = New-PSSession -ComputerName "Server1" Invoke-Command -Session $Session -ArgumentList $FilePath -ScriptBlock { $pt = New-Object System.Diagnostics.ProcessStartInfo; $pt.FileName = $args[0] ; $pt.UseShellExecute = $false; $pt.RedirectStandardInput = $true; $e = [System.Diagnostics.Process]::Start($pt); $e.StandardInput.WriteLine("`n") }
Notes:
-ComputerName argument name and $FilePath value were changed in these examples just so I could test in my environment.
The use of $FilePath instead of $Folder. So far as I can tell $pt.FileName property needs a the full path. This was either mis-typed or in error in your last sample. $FilePath because of the -FilePath parameter on Start-Process.
Get-Help Invoke-Commandfor some ideas ... [grin]powershell Invoke-Command, Google returns"About 1,000,000 results". Just searchingstackoverflow.comreturns"9,137 results". Surely there is something in ther for you.