PowerShell Mac Help - command "test.ps1" was not found, but does exist in the current location

Was hoping for assistance to a rather net-new issue. I cannot get my script to run and have tried about everything I can. Dot sourcing not working any longer and did previously. Please see full snippet below:

test.ps1: The term ‘test.ps1’ 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 “test.ps1” was not found, but does exist in the current location.

PowerShell does not load commands from the current location by default (see ‘‘Get-Help about_Command_Precedence’’).

If you trust this command, run the following command instead:

I feel its a path issue and have checked in /etc/path.d. Even added file in there to see if it would work. It did not. Also reinstalled powershell and also VScode. Pretty stuck. Any assistance would be greatly appreciated.

Thanks,

how are you trying to execute “test.ps1”? From the error message it looks like maybe you’re just typing:
test.ps1
at a pwsh prompt, and if so, the error is appropriate. I believe in order to execute a .ps1 file you have to provide the path to the file, either literal or relative.
I.e. if you’re currently in /home/UserName/' and you want to execute your "test.ps1" file but it's at /home/UserName/Powershell/Scripts` then you would have to type:

/home/UserName/Powershell/Scripts/test.ps1
# or
cd /home/UserName/Powershell/Scripts
./test.ps1

dot sourcing a .ps1 file runs it in the current scope, which is really only necessary if you need defintiions from within that ps1 to persist within your session. Dot sourcing still requires the literal or relative path to the ps1 file you wish to run, so same thing as above.

I have tried to . ./test.ps1 and also ./test.ps1. Neither work and come back with same error. I know that I am in the working directory as an “ls” shows the test.ps1 is there. Whats super strange as this has always worked. Typically, I would always . ./test.ps1 with any of my scripts, and then proceed to run it with a ./test.ps1 or just a /test.ps1. Always worked in the past. I’ve looked at about everything at this point that I could think it is, but not finding it.

just a sanity check here, but from Powershell if you’re in the directory where test.ps1 is what happens when you execute:

Test-Path ./test.ps1

?

Past that, maybe permissions?

I get the statement. “True”

Furthermore, I have a spare Mac that has never been used with powershell and get the exact same behavior. You have any idea what to look at if you think its permissions related. Both laptops are on Sonoma 14.5

Thought I would share and have no idea why this stopped working, but a lot of my scripts start off with function, then followed by the scripts inner workings. I commented out the function line and the ending bracket, and now working. Extremely odd as my scripts have had the function option forever and work previously. I’ve had a couple powershell and MAC OS updates here in the past so its only thing I can think of. You ever heard of this? As its working, I’ll move on, but really wish I knew what changed. You ever heard of anything like this?

this is all new to me. I’ve got plenty of scripts that contain function definitions as well as just script block.
BUT, a large majority of my PS execution is in Windows Powershell v5.1. The little bit i’ve done in Powershell 7.4 is on Linux and I haven’t had anything like this happen.

Would you consider taking a screenshot of your execution of “test.ps1” in terminal and paste that picture here? (it auto uploads).

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.