PowerShell 7.1.0 is not searching the current path directory (.) in the environmental path.
See original GitHub issueSteps to reproduce
1. Add the current directory (‘.’) to your the PATH variable
PS> $env:PATH = $env:PATH + ';.'
View the search directories
PS> $env:Path -split ';'
2. Create a script in a test directory
Example script:
PS> Write-Output "'Hello!'" | Set-Content Show-Hello.ps1
3. Run the script from the cmd host.
PS> Show-Hello
Expected behavior
Hello!
Actual behavior
Show-Hello: The term 'Show-Hello' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Suggestion [3,General]: The command Show-Hello was not found, but does exist in the current location. PowerShell does not load commands from the current location by default. If you trust this command, instead type: ".\Show-Hello". See "get-help about_Command_Precedence" for more details.
Environment data
Name Value
---- -----
PSVersion 7.1.0
PSEdition Core
GitCommitId 7.1.0
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
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (1 by maintainers)
Top Results From Across the Web
Setting Windows PowerShell environment variables
To be clear, the 1990's Windows way of click on Start, right click on This PC, and choose Properties, and then select Advanced...
Read more >Why is PowerShell inserting the current working directory ...
It's the current working directory. When I did something similar with PowerShell running in C:\WINDOWS\System32, I got: Could not find a ...
Read more >about Environment Variables - PowerShell
PATH. The $env:PATH environment variable contains a list of folder locations that the operating system searches for executable files. · PATHEXT.
Read more >Differences between Windows PowerShell 5.1 and ...
This article summarizes the differences and breaking changes from Windows PowerShell 5.1 and the current version of PowerShell that is based ...
Read more >Installing PowerShell on Windows
PowerShell 7.3 is installed to $env:ProgramFiles\PowerShell\7; The $env:ProgramFiles\PowerShell\7 folder is added to $env:PATH; Folders for ...
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
I question whether this should be the desired behavior for security reasons.
To be clear, all other directory nodes will be searched under PowerShell 7.1.0, EXCEPT the current directory (‘.’ or '.').
Why not allow ‘.’ paths in the search path ($env:PATH) variable?
If you read the ‘About Command Preferences’ document:
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_command_precedence?view=powershell-7.1
Here it states:
As a security feature, PowerShell does not run executable (native) commands, including PowerShell scripts, unless the command is located in a path that is listed in the Path environment variable $env:path or unless you specify the path to the script file.
I need some clarification why PowerShell v7.1.0 will no longer execute paths using the current directory (or any path using a ‘.’).
Thank you.
It does not only concern the ‘.’ path but all paths relatives to the current directory: ‘./**’