How and where to store PowerShell script

Asked By 50 points N/A Posted on -
qa-featured

 

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.

SHARE
Answered By 10 points N/A #199595

How and where to store PowerShell script

qa-featured

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.

Related Questions