Skip to content

Commit 2978120

Browse files
committed
Fix issue where MS Dynamics CRM
redefines set-content, breaks Start-PSES Fixes PowerShell/vscode-powershell#1331 I wish we didn't have to module qualify command names like this but we've been bitten several times now by overridden commands.
1 parent cfea694 commit 2978120

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

module/PowerShellEditorServices/Start-EditorServices.ps1

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,17 @@ function ExitWithError($errorString) {
102102
}
103103

104104
function WriteSessionFile($sessionInfo) {
105-
$sessionInfoJson = ConvertTo-Json -InputObject $sessionInfo -Compress
105+
$sessionInfoJson = Microsoft.PowerShell.Utility\ConvertTo-Json -InputObject $sessionInfo -Compress
106106
Log "Writing session file with contents:"
107107
Log $sessionInfoJson
108-
$sessionInfoJson | Set-Content -Force -Path "$SessionDetailsPath" -ErrorAction Stop
108+
$sessionInfoJson | Microsoft.PowerShell.Management\Set-Content -Force -Path "$SessionDetailsPath" -ErrorAction Stop
109109
}
110110

111111
# Are we running in PowerShell 2 or earlier?
112112
if ($PSVersionTable.PSVersion.Major -le 2) {
113113
# No ConvertTo-Json on PSv2 and below, so write out the JSON manually
114114
"{`"status`": `"failed`", `"reason`": `"unsupported`", `"powerShellVersion`": `"$($PSVersionTable.PSVersion.ToString())`"}" |
115-
Set-Content -Force -Path "$SessionDetailsPath" -ErrorAction Stop
115+
Microsoft.PowerShell.Management\Set-Content -Force -Path "$SessionDetailsPath" -ErrorAction Stop
116116

117117
ExitWithError "Unsupported PowerShell version $($PSVersionTable.PSVersion), language features are disabled."
118118
}
@@ -133,9 +133,9 @@ $isPS5orLater = $PSVersionTable.PSVersion.Major -ge 5
133133

134134
# If PSReadline is present in the session, remove it so that runspace
135135
# management is easier
136-
if ((Get-Module PSReadline).Count -gt 0) {
136+
if ((Microsoft.PowerShell.Core\Get-Module PSReadline).Count -gt 0) {
137137
LogSection "Removing PSReadLine module"
138-
Remove-Module PSReadline -ErrorAction SilentlyContinue
138+
Microsoft.PowerShell.Core\Remove-Module PSReadline -ErrorAction SilentlyContinue
139139
}
140140

141141
# This variable will be assigned later to contain information about
@@ -146,7 +146,7 @@ $resultDetails = $null;
146146
function Test-ModuleAvailable($ModuleName, $ModuleVersion) {
147147
Log "Testing module availability $ModuleName $ModuleVersion"
148148

149-
$modules = Get-Module -ListAvailable $moduleName
149+
$modules = Microsoft.PowerShell.Core\Get-Module -ListAvailable $moduleName
150150
if ($modules -ne $null) {
151151
if ($ModuleVersion -ne $null) {
152152
foreach ($module in $modules) {
@@ -182,7 +182,7 @@ function Test-PortAvailability {
182182
$ipAddress = [System.Net.IPAddress]::Loopback
183183
Log "Testing availability of port ${PortNumber} at address ${ipAddress} / $($ipAddress.AddressFamily)"
184184

185-
$tcpListener = New-Object System.Net.Sockets.TcpListener @($ipAddress, $PortNumber)
185+
$tcpListener = Microsoft.PowerShell.Utility\New-Object System.Net.Sockets.TcpListener @($ipAddress, $PortNumber)
186186
$tcpListener.Start()
187187
$tcpListener.Stop()
188188
}
@@ -202,7 +202,7 @@ function Test-PortAvailability {
202202
}
203203

204204
$portsInUse = @{}
205-
$rand = New-Object System.Random
205+
$rand = Microsoft.PowerShell.Utility\New-Object System.Random
206206
function Get-AvailablePort() {
207207
$triesRemaining = 10;
208208

@@ -247,7 +247,7 @@ try {
247247
LogSection "Start up PowerShellEditorServices"
248248
Log "Importing PowerShellEditorServices"
249249

250-
Import-Module PowerShellEditorServices -ErrorAction Stop
250+
Microsoft.PowerShell.Core\Import-Module PowerShellEditorServices -ErrorAction Stop
251251

252252
# Locate available port numbers for services
253253
# There could be only one service on Stdio channel

0 commit comments

Comments
 (0)