N/APosted on - 12/10/2013
I am a regular user of C and C++ and have been using them to write scripts since several years. Now I wrote my first ever PowerShell script which I would like to call it from the Posh Command line. Please tell me where and how to store the script—as a function in the profile? on my PATH? or somewhere else? Please let me know the details. I would like to see my work organized and uncluttered right from the beginning ! Thnaks in advance.
How and where to store PowerShell script
You can put your script in the same folder as your profile and then version them together. Write $script:MyInvocation.MyCommand.Path e.g.:- $ProfileRoot = (Split-Path -Parent $MyInvocation.MyCommand.Path) $env:path += ";$ProfileRoot"
Or, V2 will help you to create modules directory in the WindowsPowerShell directory where your profile is saved. Now, when you will run import-module PS will by default look in that directory to load the modules. In order to know how to save your Powershell scripts you may visit here. Hope, this may help you in your work.