I've stored commonly used powershell scripts at %USERPROFILE%\Bin
. I created a USER_BIN
environment variable which I added to the user PATH
environment variable via Control Panel > System and Security > System > Advanced system setting > Environment Variables
.
When I enter the name of a script stored in Bin
, i.e. my-script.ps1
, into a cmd or powershell prompt I get the message my-script.ps1 : The term 'my-script.ps1' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
If I provide the full-path, i.e. C:\Users\Ari\Bin\my-script.ps1
the script works fine.
Best Answer
It's a powershell security feature. You can only invoke scripts by relative or absolute path but not by file name.
The reasoning behind this decision is as follows:
Sources: http://technet.microsoft.com/en-us/magazine/2007.09.powershell.aspx http://technet.microsoft.com/en-us/library/bb613481%28v=vs.85%29.aspx