guu*_*lee 33 powershell editing powershell-remoting
我使用powershell远程连接到另一台计算机,非常好.可以做很多,但如何编辑文件?
PS C:\ Users\guutlee> Enter-PSSession -ComputerName appprod
[appprod]:PS C:\ Users\guutlee\Documents> cd\myapp
[appprod]:PS C:\ myapp>
如何在远程计算机上的文件上打开文件编辑器?
[appprod]:PS C:\ myapp>编辑app.config
所以编辑"filename"似乎挂起,来自powershell.exe或powershell_ise.exe
我唯一能想到的就是退出pssession和"start\webprod\c $\inetpub\myapp\web.config",这将打开visual studio.
[appprod]:PS C:\ myapp>退出
PS C:\ Users\guutlee> start\agobuild\c $\myapp\app.config
PS C:\ Users\guutlee> Enter-PSSession -ComputerName appprod
[appprod]:PS C:\ Users\guutlee\Documents> cd\myapp
[appprod]:PS C:\ myapp> myapp.exe
当然,我必须重新找到该文件,希望c $共享可用且可访问,并重新连接我的pssession并在我想继续时重新找到我的工作目录.它似乎并不优雅.
我可以把它包裹起来这是一个功能,但很难把我的脑袋包裹起来......
那么如何使用远程pssession方便地编辑文件?
编辑
kbrimington的帖子让我想到了ssh的-X选项.对于PowerShell会话而言,将窗口应用程序转发回原始窗口环境可能会是一件非常棒的事情......
但我仍然很高兴只是编辑文件.
编辑
使用vi,emacs,cmd和编辑测试
PS C:\ Users\Meredith> Enter-PSSession -ComputerName appprod
[appprod]:PS C:\ Users\guutlee\Documents> C:\ vim\vim72\vim filename.txt
[appprod]:PS C:\ Users\guutlee\Documents> C:\ emacs-23.2\bin\emacs.exe -nw filename.txt
emacs.exe:emacs:标准输入不是tty
Run Code Online (Sandbox Code Playgroud)+ CategoryInfo \: NotSpecified: (emacs: standard input is not a tty:String) [], RemoteException + FullyQualifiedErrorId \: NativeCommandError
[appprod]:PS C:\ Users\guutlee\Documents> cmd
Microsoft Windows [版本6.1.7600]
版权所有(c)2009 Microsoft Corporation.版权所有.
C:\ Users \用户guutlee \文件>
[appprod]:PS C:\ Users\guutlee\Documents> edit filename.txt
vi和编辑挂起(Control-C得到提示)
cmd运行,产生提示,但立即退回到powershell提示符
emacs产生错误(标准输入不是tty)
编辑
Jered建议在本地拉回文件进行编辑.我修饰了他使用pssessions而不是UNC进行复制的答案(也许这就是他的意图)
PS C:\ Users\Meredith> Invoke-Command -Session $ ps -ScriptBlock {get-content c:/inetpub/myapp/web.config}> web.config
编辑web配置
PS C:\ Users\Meredith> get-content web.config | Invoke-Command -Session $ ps -ScriptBlock {set-content c:/inetpub/myapp/web.config}
我们可以在任一方向上运行invoke-commands,本地到远程或远程返回本地.
归档时间: |
|
查看次数: |
41226 次 |
最近记录: |