Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to edit a file in powershell remoting session (powershell)
    primarykey
    data
    text
    <p>I am connecting to another computer using powershell remoting, really nice. can do lots, but how do I edit a file?</p> <blockquote> <p>PS C:\Users\guutlee> <strong>Enter-PSSession -ComputerName appprod</strong></p> <p>[appprod]: PS C:\Users\guutlee\Documents> <strong>cd \myapp</strong></p> <p>[appprod]: PS C:\myapp></p> </blockquote> <p>what can I do to open a file editor on a file on the remote machine? </p> <blockquote> <p>[appprod]: PS C:\myapp> edit app.config</p> </blockquote> <p>so edit "filename" just seems to hang, from powershell.exe or from powershell_ise.exe</p> <p>The only thing I can think of is back out of the pssession and "start \webprod\c$\inetpub\myapp\web.config", which would open visual studio. </p> <blockquote> <p>[appprod]: PS C:\myapp> exit</p> <p>PS C:\Users\guutlee> <strong>start \agobuild\c$\myapp\app.config</strong></p> <p>PS C:\Users\guutlee> <strong>Enter-PSSession -ComputerName appprod</strong></p> <p>[appprod]: PS C:\Users\guutlee\Documents> <strong>cd \myapp</strong></p> <p>[appprod]: PS C:\myapp> <strong>myapp.exe</strong></p> </blockquote> <p>Of course with this I have to re-find the file, hope that the c$ share is available and accessible, and the reconnect my pssession and re-find my working directory when I want to go on. It doesn't seem very elegant.</p> <p>I could maybe wrap this is a function, but having a hard time wrapping my head around that..</p> <p>so how do I conveniently edit a file with a remote pssession?</p> <p>EDIT</p> <p>kbrimington's post got me thinking me about the -X option to ssh. probably would be an awesome thing for powershell sessions to be able to forward windowed apps back to the original windowing environment...</p> <p>but still I'd be happy just to edit the file.</p> <p>EDIT</p> <p>tests using vi, emacs, cmd and edit</p> <blockquote> <p>PS C:\Users\Meredith> <strong>Enter-PSSession -ComputerName appprod</strong></p> <p>[appprod]: PS C:\Users\guutlee\Documents> <strong>C:\vim\vim72\vim filename.txt</strong></p> <p>[appprod]: PS C:\Users\guutlee\Documents> <strong>C:\emacs-23.2\bin\emacs.exe -nw filename.txt</strong></p> <p>emacs.exe : emacs: standard input is not a tty</p> <pre><code>+ CategoryInfo \: NotSpecified: (emacs: standard input is not a tty:String) [], RemoteException + FullyQualifiedErrorId \: NativeCommandError </code></pre> <p>[appprod]: PS C:\Users\guutlee\Documents> <strong>cmd</strong></p> <p>Microsoft Windows [Version 6.1.7600]</p> <p>Copyright (c) 2009 Microsoft Corporation. All rights reserved.</p> <p>C:\Users\guutlee\Documents></p> <p>[appprod]: PS C:\Users\guutlee\Documents> <strong>edit filename.txt</strong></p> </blockquote> <p>vi and edit hang (Control-C to get a prompt back)</p> <p>cmd runs, producing a prompt, but immediately exits back to the powershell prompt</p> <p>emacs produces the error (standard input is not a tty)</p> <p>EDIT</p> <p>Jered suggests pulling the file back locally to edit. I embellished his answer to copying using pssessions rather than UNCs (perhaps this is what he intended)</p> <blockquote> <p>PS C:\Users\Meredith> <strong>Invoke-Command -Session $ps -ScriptBlock {get-content c:/inetpub/myapp/web.config} > web.config</strong> </p> <p><em>edit web config</em></p> <p>PS C:\Users\Meredith> <strong>get-content web.config | Invoke-Command -Session $ps -ScriptBlock {set-content c:/inetpub/myapp/web.config}</strong> </p> </blockquote> <p>Potentially we could run the invoke-commands in either direction, local to remote or remote back to local. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload