question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PowerShell 7.1.0 is not searching the current path directory (.) in the environmental path.

See original GitHub issue

Steps 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:closed
  • Created 3 years ago
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
timkgithubcommented, Nov 17, 2020

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 '.').

$env:Path = <DIR1>;<DIR2>;...<DIRN>

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.

<div>about_Command_Precedence - PowerShell</div><div>Describes how PowerShell determines which command to run.</div>
1reaction
Anthony-Brenelierecommented, Jun 2, 2023

It does not only concern the ‘.’ path but all paths relatives to the current directory: ‘./**’

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found