vscode-powershell
vscode-powershell copied to clipboard
Install-VSCode.ps1 fails when run as documented in ReadMe.md
Prerequisites
- [X] I have written a descriptive issue title.
- [X] I have searched all open and closed issues to ensure it has not already been reported.
- [X] I have read the troubleshooting guide.
- [X] I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
- [X] I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
- [X] If this is a security issue, I have read the security issue reporting guidance.
Summary
ReadMe.md has a one-liner to install Visual Studio Code. However when trying to actually run that command (in Windows 10 Sandbox), it fails.
Exact commands and output in the "steps to reproduce" section below. I can create a PR that updates the ReadMe.md command to download it to a temporary file first before running it; let me know how you think this should be resolved.
PowerShell Version
PS C:\Users\WDAGUtilityAccount> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.19041.2364
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.2364
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Visual Studio Code Version
PS C:\Users\WDAGUtilityAccount> code --version
1.75.0
e2816fe719a4026ffa1ee0189dc89bdfdbafb164
x64
Extension Version
PS C:\Users\WDAGUtilityAccount> code --list-extensions --show-versions | Select-String powershell
[email protected]
Steps to Reproduce
Run the command exactly as documented in ReadMe.md:
PS C:\Users\WDAGUtilityAccount> iex (iwr https://raw.githubusercontent.com/PowerShell/vscode-powershell/main/scripts/Install-VSCode.ps1)
iwr : The response content cannot be parsed because the Internet Explorer engine is not available, or Internet
Explorer's first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again.
At line:1 char:6
+ iex (iwr https://raw.githubusercontent.com/PowerShell/vscode-powershe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotImplemented: (:) [Invoke-WebRequest], NotSupportedException
+ FullyQualifiedErrorId : WebCmdletIEDomNotSupportedException,Microsoft.PowerShell.Commands.InvokeWebRequestComman
d
I added the -UseBasicParsing parameter, and it still fails:
PS C:\Users\WDAGUtilityAccount> iex (iwr https://raw.githubusercontent.com/PowerShell/vscode-powershell/main/scripts/Install-VSCode.ps1 -UseBasicParsing)
Downloading latest Visual Studio Code (64-bit)...
You cannot call a method on a null-valued expression.
At line:556 char:17
+ ... if (-not $PSCmdlet.ShouldProcess("$installerPath $exeArgs", ' ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
However if I download the file and run it, it works fine: (after setting the execution policy to allow it)
PS C:\Users\WDAGUtilityAccount> iwr https://raw.githubusercontent.com/PowerShell/vscode-powershell/main/scripts/Install-VSCode.ps1 -UseBasicParsing -OutFile Install-VSCode.ps1
PS C:\Users\WDAGUtilityAccount> .\Install-VSCode.ps1
Downloading latest Visual Studio Code (64-bit)...
Installing extension ms-vscode.PowerShell...
Installing extensions...
Installing extension 'ms-vscode.powershell'...
(node:1172) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use `Code --trace-deprecation ...` to show where the warning was created)
Extension 'ms-vscode.powershell' v2023.1.0 was successfully installed.
Installation complete!
PS C:\Users\WDAGUtilityAccount>
Visuals
No response
Logs
No response
Does the same thing happen with PowerShell 7?
Yes:
PowerShell 7.3.2
PS C:\Program Files\PowerShell\7> iex (iwr https://raw.githubusercontent.com/PowerShell/vscode-powershell/main/scripts/Install-VSCode.ps1)
InvalidOperation:
Line |
494 | if ($PSCmdlet.ShouldProcess($codePlatformInfo.FileUri, "Invok …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| You cannot call a method on a null-valued expression.
PS C:\Program Files\PowerShell\7> $PSVersionTable
Name Value
---- -----
PSVersion 7.3.2
PSEdition Core
GitCommitId 7.3.2
OS Microsoft Windows 10.0.19041
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Huh. @SeeminglyScience any ideas?
Thanks @ndabas looks like we are having an issue with nested parameter binding
It's basically the same problem as documented in https://github.com/PowerShell/PowerShell/issues/8816. The issue itself is https://github.com/PowerShell/PowerShell/issues/8815.
Interestingly, $PSCmdlet seems to be available when calling functions defined inside the script called by iex. It's just the top-level code that doesn't get $PSCmdlet because it is essentially dot-sourced into the current context.
A fix might be to move all top-level code into a function, then call that function. I can test and do a PR for that if you'd like.