Welcome to ciysys blog

Preload your favorite scripts in PowerShell

Published on: 14th May 2020

Updated on: 16th Jan 2022

Explanation

Try this: if you have developed many useful scripts for yourself, how to avoid calling Import-Module in all your new scripts before using them?

To solve this, we must find a way to preload your favorites. The trick is to create a profile.ps1 file and save it in your profile path. You will find your profile path by executing the following code:

$profile.CurrentUserAllHosts

After you have found out the path, create a profile.ps1 and write all Import-Module lines and functions. Then, you may run PowerShell that will create a new session and load all the contents in the profile.ps1.

Notes

Jump to #POWERSHELL blog

Author

Lau Hon Wan, software developer.