PS> $env:PATH = $env:PATH + ';.'
View the search directories
PS> $env:Path -split ';'
Example script:
PS> Write-Output "'Hello!'" | Set-Content Show-Hello.ps1
PS> Show-Hello
Hello!
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.
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
I assume that this was the desired behaviour for security reasons. If you want to run something in the current directory you need to prefix it with ./ (.\ on Windows).
Yep, the error message emits that suggestion as well:
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.
(from the OP)
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:
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.
Describes how PowerShell determines which command to run.
"no longer"? Was there a version of PowerShell this worked?
In my experience, it's always been this way for PowerShell.
It sounds like you are not aware or have never set up your environment path to search for PowerShell scripts. This is a very useful feature to customize your PowerShell environment.
The environmental search path for '.' works under 5.x, 6.x, and 7.0.x, but does not search '.' under 7.1.1.
| PowerShell Version | $env:Path - Search current directory allowed? |
| :--- | :---- |
| 5.x | YES |
| 6.x | YES |
| 7.0.x | YES |
| 7.1.0 | NO |
Yeah, personally I've never felt the need. Thanks for clarifying that!
I'm unsure if this was a regression or an intentional change, though. @iSazonov, do you know of any PRs that went in during the 7.1 release cycle that may have altered this behaviour?
I did some more testing, and have resolved the issue.
# 'Microsoft.PowerShell_profile.ps1'
# Set current path
$env:Path = $env:Path + ';.'
This will set the $envPath variable, but PWSH will not search the '.' path.
# Open new PWSH
PS> $env:Path = $env:Path + ';.'
The PowerShell 'Microsoft.PowerShell_profile.ps1' will set security information on the PATH environment variable to prevent any '.' paths from the search. This security check must have been added in the v7.1.0 release.
To work around this, current directory (.) to $env:Path after opening PWSH.
I will consider this issue resolved/closed.
Thanks all.