Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I edit text remotely in Windows

(Note, this question is also posted on technet)

How can I remotely edit a text file in Windows?

I am running and administering a number of Windows 7 workstations and Windows Server 2012 machines. I would like to be able to remotely edit text files on any of these machines. I can connect to any of these machines via psexec or powershell remoting. I can also connect via rdp, but for the workstations I would rather not kick the user off unless I absolutely have to.

For example, we manage state configuration using Salt. Local configuration files are stored in C:\salt\conf. I would like to be able to edit these config files on the fly.

This question covers the same topic, but none of the answers are particularly satisfying.

Some of the possible solutions are:

  • Remote Desktop: as I say, I would rather not have to kick a user off their workstation
  • Edit a file over a UNC path: this only works for files on a share, and setting up arbitrary shares for quick edits seems like a bad idea.
  • Install some manner of ftp or ssh server on all the target computers. This would certainly work, but it is it necessary with WinRM already active? I feel like installing and configuring extra software across all the machines in my organisation would be a last resort.
  • Edit with a command line editor (e.g. vim, emacs) over a remote powershell session. This doesn't work. I don't understand the technical details, but a powershell remote session isn't interactive in the same way that ssh connections are.
  • Edit using powershell's -replace operator, out-file and add-content cmdlets. This works, but is hardly the same as a fully featured text editor.
  • Retrieve content from the remote, edit locally, and post back to the remote. This works, and is arguably the best solution I've found. Code sample from the previous SO question:
PS C:\Users\Meredith> Invoke-Command -Session $ps -ScriptBlock {get-content c:/inetpub/myapp/web.config} > web.config

Edit web config:

PS C:\Users\Meredith> get-content web.config | Invoke-Command -Session $ps -ScriptBlock {set-content c:/inetpub/myapp/web.config}

The last two options are the workflow that I've been using for now. Regex replacement for very simple changes, and copying to local and editing there for more complicated ones. Neither is ideal, but they work. It just feels incredibly old fashioned.

I'm considering writing a plugin to my editor of choice (vim) to perform the remote fetch and save, to make my workflow a little bit smoother. Before I try that, I just want to know if there's anything that I've missed, or misunderstood.

like image 776
laffoyb Avatar asked Nov 14 '14 14:11

laffoyb


People also ask

Does Windows CMD have a Text Editor?

The 64-bit versions of Windows do not support the edit command in the Windows command line. If you need to edit files from the command line, we suggest using the notepad command from the command line as shown in the example below.


1 Answers

Use administrative shares. These are created by default on Windows, and they take the form of a drive letter followed by a $, like this: \\machine\c$

A $ in any share name makes it "hidden" (as in it won't show up when browsing \\machine\).

like image 78
briantist Avatar answered Sep 28 '22 03:09

briantist