Skip to content

Commit 33cb421

Browse files
Merge pull request #599 from tylerl0706/fix-content-calls-and-computer-name
fix *-Content calls in psedit scripts and set ComputerName to MachineName and give it a default
2 parents a141b64 + 1ff410d commit 33cb421

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/PowerShellEditorServices/Session/RemoteFileManager.cs

+23-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,17 @@ public class RemoteFileManager
4747
$filePathName = $_.FullName
4848
4949
# Get file contents
50-
$contentBytes = Get-Content -Path $filePathName -Raw -Encoding Byte
50+
$params = @{ Path=$filePathName; Raw=$true }
51+
if ($PSVersionTable.PSEdition -eq 'Core')
52+
{
53+
$params['AsByteStream']=$true
54+
}
55+
else
56+
{
57+
$params['Encoding']='Byte'
58+
}
59+
60+
$contentBytes = Get-Content @params
5161
5262
# Notify client for file open.
5363
New-Event -SourceIdentifier PSESRemoteSessionOpenFile -EventArguments @($filePathName, $contentBytes) > $null
@@ -85,7 +95,18 @@ public class RemoteFileManager
8595
[byte[]] $Content
8696
)
8797
88-
Set-Content -Path $RemoteFilePath -Value $Content -Encoding Byte -Force 2>&1
98+
# Set file contents
99+
$params = @{ Path=$RemoteFilePath; Value=$Content; Force=$true }
100+
if ($PSVersionTable.PSEdition -eq 'Core')
101+
{
102+
$params['AsByteStream']=$true
103+
}
104+
else
105+
{
106+
$params['Encoding']='Byte'
107+
}
108+
109+
Set-Content @params 2>&1
89110
";
90111

91112
#endregion

src/PowerShellEditorServices/Session/SessionDetails.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static PSCommand GetDetailsCommand()
5656
{
5757
PSCommand infoCommand = new PSCommand();
5858
infoCommand.AddScript(
59-
"@{ 'computerName' = $env:ComputerName; 'processId' = $PID; 'instanceId' = $host.InstanceId }");
59+
"@{ 'computerName' = if ([Environment]::MachineName) {[Environment]::MachineName} else {'localhost'}; 'processId' = $PID; 'instanceId' = $host.InstanceId }");
6060

6161
return infoCommand;
6262
}

0 commit comments

Comments
 (0)