Note for those finding this - mklement0's comment worked for me.
The issue is that this .ps1 is a function definition, not a function invocation. The file defines a function but doesn't invoke it.
In order to invoke it from the command line, you need to either add it to your PowerShell environment or remove the function {} wrapper.
One way to add to your environment is to dot-source the file - in this case
. FindGitRepository
which returns with no result, then FindGitRepository. This worked for me in VSCode.
If you want to just run this command (FindGitRepository), you need to either
add it to your profile, etc so it's part of your environment or
remove the function definition and just execute the commands.
===================
Didn't see anything like this in SE question list - there are questions about PS scripts working in ISE but not terminal, but those all seem to be about scripts the OPs are writing that are making system calls, library calls, etc.
This script is not mine, but reading through it does not seem to be making any library calls. Also, why isn't there an error message?
Situation
I'd like to run this powershell script to list metadata on my git repositories - https://jdhitsolutions.com/blog/powershell/4999/finding-git-repositories-with-powershell/
Saved script content as local file c:\tools\Find-GitRepository.ps1 with content.
When I run this in PSE, it completes with results.
PS C:\tools> Find-GitRepository -path d:\projects\
Repository Branch LastAuthor LastLog
----- ------ ---------- -------
D:\projects\gitpro main <correct owner> 8/1/2023 17:18:28
(expected output, list of git repos. etc)
- When I run this in a normal terminal session, admin terminal session, VS Code etc, it completes with no feedback.
PS c:\tools\> powershell.exe .\Find-GitRepository.ps1 -path d:\projects
PS c:\tools>
(no error thrown or output)
(without leading space)
PS c:\tools> Find-GitRepository.ps1 -path d:\projects
PS c:\tools>
Suggestion [3,General]: The command Find-GitRepository was not found, but does exist in the current location. PowerShell does not load commands from the current location...
what I've tried that doesn't work
- tried running in
- terminal console,
- terminal admin,
- vs code
- a script specifying c:\windows\powershell\7\pwsh.exe --program, etc).
- running after running
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
all run and return to the c:\tools prompt with no output.