(I can't believe I'm actually asking this, but I am out of brainpower for the day.)

I just wrote my first serious PowerShell script, and I'm really happy with it. I plan to use it every day or so. I want to be able to call it from the Posh command line. I'll give it a verb-noun type name, but for now it's a simple .ps1 and not one of those fancy advanced functions that take params and such.

So where should it go and how do I call it from a Posh command line? I plan to write more! Where should they go?

Should it be a function in my profile?

Should it go on my path?

Does it go in a PSMODULEPATH? What kind of stuff goes there anyway? Does it look recursively or is it just like the normal PATH?

Where do you all put your PowerShell scripts and how do you organize them? I've got a lot of experience making C# and C++ tools and know what to name them and where to put them. And at the other extreme I've done a lot of crappy .bat files which are usually standalone or piled in a heap in some folder. But PowerShell seems to be very different. You can make crappy .bat file type things in it really quickly, or you can be building libraries and sophisticated services with it.

I'd really love some ideas on how I should start organizing these things before I start. Obviously everybody is different, so I'm hoping for some discussion. Thanks!

use $script:MyInvocation.MyCommand.Path, see source path of an executing script. You get into problems with nested callers, even with the profile script, for example I have a helper function to reload your profile (after function/variable edits) but skip all one-time init (like loading .NET assemblies).
–
yzorgMay 31 '12 at 18:32

With V2, you can create a modules directory in the WindowsPowerShell directory where your profile is. PS will automatically look in that directory to load modules when you run import-module. I created a "Scripts" directory under WindowsPowerShell as well that is a sibling directory of Modules.

I use my profile to set some directories using variables with the following code:

This is what I do as well. Though I also have a "Libraries" directory with scripts that my profile auto executes to define global functions. I did that in PowerShell v1, I will probably replace all that with Modules eventually.
–
JasonMArcherJun 28 '09 at 0:02