vscode-powershell icon indicating copy to clipboard operation
vscode-powershell copied to clipboard

Remote editing only works for .ps1 files but not others

Open OnurGumus opened this issue 6 years ago • 50 comments

When I follow this documentation https://docs.microsoft.com/en-us/powershell/scripting/components/vscode/using-vscode-for-remote-editing-and-debugging?view=powershell-6

I noticed remote editing only works for .ps1 files. For other extensions, you can save the file but it won't sync back to the server. I am using PowerShell v7 preview 3 for both host and server and both host and server are windows machines along with Latest VSCode and Powershell extension

A relevant issue has been earlier reported but closed: https://github.com/PowerShell/vscode-powershell/issues/1040

OnurGumus avatar Sep 04 '19 07:09 OnurGumus

@OnurGumus thanks for opening this issue...It would be really helpful if you could also attach the logs--instructions for how to do that are here , please also provide repro steps, as well as a detailed description of the behavior you are experiencing...thanks!

SydneyhSmith avatar Sep 05 '19 21:09 SydneyhSmith

@SydneyhSmith all repo steps has been clearly stated in the opening issue. If you actually spend 2 minutes and read what I wrote, you will understand the problem. I am not intended to provide further info regarding how to reproduce and loggings as the issue and repro steps are crystal clear.

OnurGumus avatar Sep 06 '19 06:09 OnurGumus

@OnurGumus I just followed the steps, and the file saves as expected.

before: image

after I added a line in the editor: image

We need the logs because something might be specific to your system. Please provide those and also what OS's you're using.

Also, do you have access to the file you're trying to save?

TylerLeonhardt avatar Sep 06 '19 16:09 TylerLeonhardt

@TylerLeonhardt, if you read the issue carefully, it clearly states both server and client are windows machines. In your case you are using Linux.

To be specific client is latest windows 10 pro rtm X64 and server is windows server 2019 standard edition 1809.

I am creating the file with new item. Saving only works when the extension is ps1. Also you use a different command than the linked tutorial as new-editor-file whereas I am using psedit, not sure if it makes any difference.

OnurGumus avatar Sep 06 '19 17:09 OnurGumus

I will provide the logs once I have access to my computer.

OnurGumus avatar Sep 06 '19 17:09 OnurGumus

Missed the part about Windows. My bad. Just for future reference, we have an issue template so that we don't miss these details the first time around. It just streamlines the process.

New-EditorFile creates a file and opens it in vscode. It's the equivalent to New-Item and then psedit (which is an alias of Open-EditorFile).

I still need to know - what communication protocol are you using? ssh or winrm?

TylerLeonhardt avatar Sep 06 '19 17:09 TylerLeonhardt

It's winrm. I agree that my writing style makes those details less visible. But I thought your template was really overwhelming since it was easy to repro from my point of view.

OnurGumus avatar Sep 07 '19 02:09 OnurGumus

@OnurGumus we will try to stand up an environment similar to yours and repro this...in the meantime it would still be helpful to see your logs--thanks!

SydneyhSmith avatar Sep 10 '19 21:09 SydneyhSmith

Hi, I'm having the same issue from Windows 10 PC to Windows Server Reproduced both with 6.2 and 7-preview3

My prompt and logs attached

[npe-file-01]: PS C:\Users\majohnson_admin\Documents> "Test" > test.ps1
[npe-file-01]: PS C:\Users\majohnson_admin\Documents> Get-Content test.ps1
Test
[npe-file-01]: PS C:\Users\majohnson_admin\Documents> psedit test.ps1
[npe-file-01]: PS C:\Users\majohnson_admin\Documents> Get-Content test.ps1
Edited
[npe-file-01]: PS C:\Users\majohnson_admin\Documents> "Test" > test.txt
[npe-file-01]: PS C:\Users\majohnson_admin\Documents> Get-Content test.txt
Test
[npe-file-01]: PS C:\Users\majohnson_admin\Documents> psedit test.txt
[npe-file-01]: PS C:\Users\majohnson_admin\Documents> Get-Content test.txt
Test
[npe-file-01]: PS C:\Users\majohnson_admin\Documents>

1568362690-2cf65ee5-9dce-4f0e-b10e-421124476b0e1568360608478.zip

centreboard avatar Sep 13 '19 08:09 centreboard

This issue is being closed as inactive, if this issue is still occurring it will be re-opened

ghost avatar Sep 18 '19 12:09 ghost

@SydneyhSmith I'm still having this issue. Let me know if you need any further information

centreboard avatar Sep 18 '19 12:09 centreboard

Faced the same issue today (Windows 10 with Powershell 5). Is any additional information required? (This issue is still labelled as 'Needs-Repro-Info')

mkarpuk avatar Oct 25 '19 12:10 mkarpuk

@SydneyhSmith may I ask why you remove Needs:Attention?

OnurGumus avatar Nov 29 '19 08:11 OnurGumus

The "Needs: Attention" label is only applied if someone said something after we have:

  • Responded
  • Determined the issue should be closed
  • Determined the issue should remain open

We acknowledge this bug (it's still open and has the Issue-Bug label) but we haven't made progress on it yet to report anything back. It's not the highest priority issue compared to others but when we have resources to spend some time in this space I promise to give an update.

We removed that label because we have nothing to report back or add to the conversation.

TylerLeonhardt avatar Dec 19 '19 18:12 TylerLeonhardt

@TylerLeonhardt it's you to decide the priorities but allow me to explain the impact of this. Right now it's impossible to edit a remote file through powershell remoting by any means from windows to windows. Sounds pretty serious to me.

OnurGumus avatar Dec 20 '19 04:12 OnurGumus

I've been looking into this this week, but haven't been able to reproduce any issues remoting into Windows PowerShell 5.1 on Windows Server 2016 or 2019, from PowerShell 5.1 or 7. One example:

psedit

@OnurGumus, @centreboard, @mkarpuk, @dylan-azucena would you be able to share the following details of your setup please:

  • The name and version of the OS you're remoting from
  • The version of PowerShell you're remoting from
  • The name and version of the OS you're remoting to
  • The version of PowerShell you're remoting to
  • The remoting command you used — in particular, we need to know whether you're using WSMan (-ComputerName) or SSH (-HostName)

To get the OS name and version, try:

systeminfo | select -first 2 -skip 2

which should have an output like:

OS Name:                   Microsoft Windows Server 2019 Datacenter
OS Version:                10.0.17763 N/A Build 17763

To get the PowerShell version, try $PSVersionTable.

rjmholt avatar Jan 15 '20 20:01 rjmholt

@rjmholt I'm no longer seeing the issue, I attempted your test and was able to remotely edit a txt file and save it successfully.

FWIW:

Remoting From

OS: macos Catalina (10.15.2) PS: 6.2.3 Core

Remoting To

OS: Microsoft Windows Server 2016 Datacenter (10.0.14393 N/A Build 14393) PS: 5.1.14393.3053 Desktop

Command

Enter-PSSession -ComputerName $server -Credential $admin -Authentication basic -UseSSL -SessionOption $pso

dylan-azucena avatar Jan 15 '20 20:01 dylan-azucena

I've just tested this remoting over SSH from PS 7-rc.1 to 6.2.3 and PS 7 to 7 and was able to save the file like in the GIF above.

Hopefully we can collect more information to determine what might be causing this on some systems.

rjmholt avatar Jan 15 '20 21:01 rjmholt

@rjmholt what is your source operating system?

OnurGumus avatar Jan 16 '20 06:01 OnurGumus

@dylan-azucena you are trying from Mac. The issue is from windows to windows.

The problem still exists by the way. I have just tested today: Source OS : windows 10 x64 1903, Powershell 7.0 rc1 Target OS : Windows 2019 x64 Standard edition 1809

OnurGumus avatar Jan 16 '20 06:01 OnurGumus

@OnurGumus

Target OS : Windows 2019 x64 Standard edition 1809

Could you specify the version of PowerShell you're trying to remote into and the remoting command you're using to do it?

rjmholt avatar Jan 16 '20 06:01 rjmholt

@rjmholt what is your source operating system?

OS Name:                   Microsoft Windows 10 Enterprise Insider Preview
OS Version:                10.0.19535 N/A Build 19535

rjmholt avatar Jan 16 '20 06:01 rjmholt

@rjmholt Source:

PowerShell 7.0.0-rc.1
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/powershell
Type 'help' to get help.

PS C:\Users\Onur.Gumus>  systeminfo | select -first 2 -skip 2
OS Name:                   Microsoft Windows 10 Pro
OS Version:                10.0.18363 N/A Build 18363

Target:

PowerShell 7.0.0-rc.1
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/powershell
Type 'help' to get help.

PS C:\Users\gatesdev>  systeminfo | select -first 2 -skip 2
OS Name:                   Microsoft Windows Server 2019 Standard
OS Version:                10.0.17763 N/A Build 17763

OnurGumus avatar Jan 16 '20 06:01 OnurGumus

@OnurGumus are you remoting with a command like this:

$s = New-PSSession -HostName $ipAddress -Credential $credential
Enter-PSSession $s

Or are you using a different command (perhaps WSMan-based?)

rjmholt avatar Jan 16 '20 06:01 rjmholt

For my own reference, this is the relevant code path:

rjmholt avatar Jan 16 '20 06:01 rjmholt

@rjmholt I am not using SSH. I am using this

Enter-PSSession -ComputerName  $ipAddress -Credential $credential

OnurGumus avatar Jan 16 '20 06:01 OnurGumus

@centreboard looking through your logs I see the following notifications (in chronological order) about test.txt:

2019-09-13 09:19:59.634 [VERBOSE] tid:5 in 'ExecuteCommand' C:\PowerShellEditorServices\src\PowerShellEditorServices\Session\PowerShellContext.cs: line 492
    Attempting to execute command(s):
    
        "Test" > test.txt
        Out-Default
2019-09-13 09:20:08.430 [VERBOSE] tid:27 in 'ExecuteCommand' C:\PowerShellEditorServices\src\PowerShellEditorServices\Session\PowerShellContext.cs: line 492
    Attempting to execute command(s):
    
        Get-Content test.txt
        Out-Default
2019-09-13 09:20:12.909 [VERBOSE] tid:7 in 'ExecuteCommand' C:\PowerShellEditorServices\src\PowerShellEditorServices\Session\PowerShellContext.cs: line 492
    Attempting to execute command(s):
    
        psedit test.txt
        Out-Default
2019-09-13 09:20:12.977 [VERBOSE] tid:6 in 'WriteMessage' C:\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageWriter.cs: line 88
    Writing Request 'editor/openFile' with id 2
    
    {
      "jsonrpc": "2.0",
      "id": "2",
      "method": "editor/openFile",
      "params": {
        "filePath": "C:\\Users\\majohnson\\AppData\\Local\\Temp\\PSES-3636\\RemoteFiles\\964015699\\NPE-FILE-01\\test.txt",
        "preview": true
      }
    }
2019-09-13 09:20:23.631 [VERBOSE] tid:27 in 'ExecuteCommand' C:\PowerShellEditorServices\src\PowerShellEditorServices\Session\PowerShellContext.cs: line 492
    Attempting to execute command(s):
    
        Get-Content test.txt
        Out-Default
2019-09-13 09:20:25.797 [VERBOSE] tid:7 in 'WriteMessage' C:\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageWriter.cs: line 88
    Writing Request 'editor/closeFile' with id 4
    
    {
      "jsonrpc": "2.0",
      "id": "4",
      "method": "editor/closeFile",
      "params": "C:\\Users\\majohnson\\AppData\\Local\\Temp\\PSES-3636\\RemoteFiles\\964015699\\NPE-FILE-01\\test.txt"
    }

There doesn't seem to be a textDocument/saveFile notification for test.txt in the logs, only test.ps1. That notification is something that VSCode (not the PowerShell extension) sends when you save a file.

Given that information, it might be worth making sure your VSCode version is up to date and trying to reproduce the issue with the following steps (or let me know if you used different steps):

  • Open the Integrated Console
  • Enter a PSSession on the remote machine
  • Create a file with PowerShell (like New-Item ./test.txt -Value 'Test')
  • Edit the file in VSCode with psedit
  • Save the file from VSCode (as you would an ordinary local file)
  • Check the content of the file from PowerShell (e.g. with Get-Content ./test.txt)

If the problem persists, please upload your logs again so we can take a look. If you could also capture a GIF of what's happening, that would be ideal.

rjmholt avatar Jan 16 '20 06:01 rjmholt

@OnurGumus

I am using this

Enter-PSSession -ComputerName $ipAddress -Credential $credential

Are you using a -ConfigurationName? Without that parameter, you will remote into Windows PowerShell 5.1.

In either case, I've followed the remote file editing steps over WSMan from 7-rc.1 both without a configuration name (remoting into 5.1) and with a configuration name (remoting into 7-rc.1), but haven't yet been able to reproduce the issue:

remoteedit

It might be worth seeing if there's anything recorded in the logs that helps. If you're using the preview extension, you'll need to grab the payload logs to catch the messages.

rjmholt avatar Jan 16 '20 07:01 rjmholt

@rjmholt Thanks for the effort. I was not using -ConfigurationName. When I tried below

Enter-PSSession -ComputerName 192.168.63.25 -Credential gatesdev -ConfigurationName 'Powershell.7'

Enter-PSSession: Connecting to remote server 192.168.63.25 failed with the following error message : The WS-Management service cannot process the request. Cannot find the Powershell.7 session configuration in the WSMan: drive on the 192.168.63.25 computer. For more information, see the about_Remote_Troubleshooting Help topic.

OnurGumus avatar Jan 16 '20 09:01 OnurGumus

@rjmholt could it be because I set the remoting long time ago against powershell 6?

OnurGumus avatar Jan 16 '20 09:01 OnurGumus