else: The term 'else' is not recognized as a name of a cmdlet, function, script file, or executable program.
See original GitHub issueIssue Description
I am experiencing a problem with… else is not recognized as a name of a cmdlet, function, script file, or executable program when using the “Format Document” feature.
Format Document (creates the error)
$x = 5
if ($x -eq 5) {
"x = 5"
}
else {
"x not equal 5"
}
Manual edit (now works)
$x = 5
if ($x -eq 5) {
"x = 5"
}else {
"x not equal 5"
}
BOTH of these work when run from PowerShell ISE or running the code via a normal powershell console. vscode for some reason does not like else being on a new line. This behaviour is the same for Windows PowerShell 5.2 and PowerShell 7.1.0
I use Format Document for all my scripts and I’ve never run into this issue with ‘else’ previously so do not know if this is a new bug introduced recently??
Environment Information
Visual Studio Code
Name | Version |
---|---|
Operating System | Windows_NT x64 10.0.14393 |
VSCode | 1.51.1 |
PowerShell Extension Version | 2020.6.0 |
PowerShell Information
Name | Value |
---|---|
PSVersion | 7.1.0 |
PSEdition | Core |
GitCommitId | 7.1.0 |
OS | Microsoft Windows 10.0.14393 |
Platform | Win32NT |
PSCompatibleVersions | 1.0 2.0 3.0 4.0 5.0 5.1.10032.0 6.0.0 6.1.0 6.2.0 7.0.0 7.1.0 |
PSRemotingProtocolVersion | 2.3 |
SerializationVersion | 1.1.0.1 |
WSManStackVersion | 3.0 |
Visual Studio Code Extensions
Visual Studio Code Extensions(Click to Expand)
Extension | Author | Version |
---|---|---|
better-comments | aaron-bond | 2.1.0 |
powershell | ms-vscode | 2020.6.0 |
vscode-icons | vscode-icons-team | 11.0.0 |
vscode-theme-onedark | akamud | 2.2.2 |
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (2 by maintainers)
Top Results From Across the Web
The term 'else' is not recognized as the name of a cmdlet
else : The term 'else' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling...
Read more >The term 'else' is not recognized as the name of a cmdlet ...
locked. else : The term 'else' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the...
Read more >else: The term 'else' is not recognized as the name of a cmdlet ...
Error : powershell else: The term 'else' is not recognized as the name of a cmdlet, function, script file, or operable program.
Read more >How To Fix 'the term is not recognized as the name of a cmdlet ...
If the module is missing or damaged, PowerShell won't be able to execute it. By default, you have to install modules in the...
Read more >The term 'else' is not recognized as the name of a cmdlet ...
Powershell seems to consider the else block as separate statement, not attached to ... as the name of a cmdlet, function, script file,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That’s because pressing F8 when dealing with “not the PowerShell Integrated Console” just throws the text in the editor into the terminal window.
With the “PowerShell Integrated Console”, we do something differently (sending a message behind the scenes with the full script to make sure the full script gets run). We can do this because it’s “Integrated”.
I’m not sure what can really be done about this behavior unless PSReadLine supported Paste Bracketing: https://github.com/PowerShell/PSReadLine/issues/1471
done 👍