how to edit a file in powershell remoting session (powershell) how to edit a file in powershell remoting session (powershell) powershell powershell

how to edit a file in powershell remoting session (powershell)


If you are using Powershell 5, you can use command called PSEdit. It only works from ISE.

  1. So first, open PowerShell ISE
  2. Then open remote session to the remote computer using Enter-PSSession
  3. Then edit the file using PsEdit 'filename'

The remote file will be opened in a new tab in your (local) ISE window.

Actually I found this answer from the comments section of this SO question , but I think it will be helpful for others if I post it as answer here.


Can you not pull the file locally, edit it and post it? I know this is tedious and not elegant but it seems editors are presently having issue with remote sessions.

E.g.,

Get-Content REMOTE\Filename.txt > LOCAL\Filename.txt

Make your changes locally and then

Set-Content -path REMOTE\Filename.txt -value (get-content LOCAL\Filename.txt)

EDIT

Also if you are only replacing certain instances you can do this pretty easily.

E.g.,

Get-Content REMOTE\Filename.txt | foreach-object { $_ -replace "OLD", "NEW" } | Set-Content REMOTE\Filename.txt


After much digging around, I found something that seems relevant in the powershell help documentation. At the powershell prompt, type:

help about_remote_troubleshooting

At the very end of the help file that is displayed, there is a section entitled 'TROUBLESHOOTING UNRESPONSIVE BEHAVIOUR', which states:

TROUBLESHOOTING UNRESPONSIVE BEHAVIOR

This section discusses remoting problems that prevent a command from completing and prevent or delay the return of the Windows PowerShell prompt.

HOW TO INTERRUPT A COMMAND


Some native Windows programs, such as programs with a user interface, console applications that prompt for input, and console applications that use the Win32 console API, do not work correctly in the Windows PowerShell remote host.

When you use these programs, you might see unexpected behavior, such as no output, partial output, or a remote command that does not complete. To end an unresponsive program, type CTRL + C. To view any errors that might have been reported, type "$error" in the local host and the remote session.

Thus it would seem even non-GUI console applications such as VIM won't work unfortunately. Anyonecare to shed a little light on why this might be the case and/or whether it can be workedaround? I would REALLY love it if I could use vim over powershell remoting.