diff --git a/src/PowerShellEditorServices/Session/RemoteFileManager.cs b/src/PowerShellEditorServices/Session/RemoteFileManager.cs index 194c5932b..c36582fab 100644 --- a/src/PowerShellEditorServices/Session/RemoteFileManager.cs +++ b/src/PowerShellEditorServices/Session/RemoteFileManager.cs @@ -47,7 +47,17 @@ public class RemoteFileManager $filePathName = $_.FullName # Get file contents - $contentBytes = Get-Content -Path $filePathName -Raw -Encoding Byte + $params = @{ Path=$filePathName; Raw=$true } + if ($PSVersionTable.PSEdition -eq 'Core') + { + $params['AsByteStream']=$true + } + else + { + $params['Encoding']='Byte' + } + + $contentBytes = Get-Content @params # Notify client for file open. New-Event -SourceIdentifier PSESRemoteSessionOpenFile -EventArguments @($filePathName, $contentBytes) > $null @@ -85,7 +95,18 @@ public class RemoteFileManager [byte[]] $Content ) - Set-Content -Path $RemoteFilePath -Value $Content -Encoding Byte -Force 2>&1 + # Set file contents + $params = @{ Path=$RemoteFilePath; Value=$Content; Force=$true } + if ($PSVersionTable.PSEdition -eq 'Core') + { + $params['AsByteStream']=$true + } + else + { + $params['Encoding']='Byte' + } + + Set-Content @params 2>&1 "; #endregion diff --git a/src/PowerShellEditorServices/Session/SessionDetails.cs b/src/PowerShellEditorServices/Session/SessionDetails.cs index 0708dae01..708e6ec9d 100644 --- a/src/PowerShellEditorServices/Session/SessionDetails.cs +++ b/src/PowerShellEditorServices/Session/SessionDetails.cs @@ -56,7 +56,7 @@ public static PSCommand GetDetailsCommand() { PSCommand infoCommand = new PSCommand(); infoCommand.AddScript( - "@{ 'computerName' = $env:ComputerName; 'processId' = $PID; 'instanceId' = $host.InstanceId }"); + "@{ 'computerName' = if ([Environment]::MachineName) {[Environment]::MachineName} else {'localhost'}; 'processId' = $PID; 'instanceId' = $host.InstanceId }"); return infoCommand; }