(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:
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.
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.
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\
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With