Friday, 15 March 2013

powershell - How do I edit text remotely in Windows -



powershell - How do I edit text remotely in Windows -

(note, question posted on technet)

how can remotely edit text file in windows?

i running , administering number of windows 7 workstations , windows server 2012 machines. able remotely edit text files on of these machines. can connect of these machines via psexec or powershell remoting. can connect via rdp, workstations rather not kick user off unless absolutely have to.

for example, manage state configuration using salt. local configuration files stored in c:\salt\conf. able edit these config files on fly.

this question covers same topic, none of answers particularly satisfying.

some of possible solutions are:

remote desktop: say, rather not have kick user off workstation edit file on unc path: works files on share, , setting arbitrary shares quick edits seems bad idea. install manner of ftp or ssh server on target computers. work, necessary winrm active? sense installing , configuring software across machines in organisation lastly resort. edit command line editor (e.g. vim, emacs) on remote powershell session. doesn't work. don't understand technical details, powershell remote session isn't interactive in same way ssh connections are. edit using powershell's -replace operator, out-file , add-content cmdlets. works, hardly same featured text editor. retrieve content remote, edit locally, , post remote. works, , arguably best solution i've found. code sample previous question: class="lang-none prettyprint-override">ps c:\users\meredith> invoke-command -session $ps -scriptblock {get-content c:/inetpub/myapp/web.config} > web.config

edit web config:

class="lang-none prettyprint-override">ps c:\users\meredith> get-content web.config | invoke-command -session $ps -scriptblock {set-content c:/inetpub/myapp/web.config}

the lastly 2 options workflow i've been using now. regex replacement simple changes, , copying local , editing there more complicated ones. neither ideal, work. feels incredibly old fashioned.

i'm considering writing plugin editor of selection (vim) perform remote fetch , save, create workflow little bit smoother. before seek that, want know if there's i've missed, or misunderstood.

use administrative shares. these created default on windows, , take form of drive letter followed $, this: \\machine\c$

a $ in share name makes "hidden" (as in won't show when browsing \\machine\).

windows powershell text psexec winrm

No comments:

Post a Comment