Avatar of KC2TC
KC2TC
Flag for United States of America asked on

Powershell library

I want to create a powershell library and use the functions in my powershell script.Can anybody help me out.
Powershell

Avatar of undefined
Last Comment
Brent Challis

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Gary Dewrell

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Brent Challis

The way that I use a module for the functionality that I want to be able to use easily is that I have a directory named for my module, and the psm1 file of the same name it in it.  In my case, the directory is:
C:\Users\bchallis\Documents\WindowsPowerShell\Modules\PBCPSModule

and the file is called:
PBCPSModule.psm1

In my case the file contains instructions to load the files that make up the functionality that I want:
. $psScriptRoot\GeneralUtilities.ps1
. $psScriptRoot\CompareObjectOutput.ps1
. $psScriptRoot\GetDownloadQuotaLevel.ps1
. $psScriptRoot\GetFileSizesByType.ps1
. $psScriptRoot\ManageBCServices.ps1
. $psScriptRoot\NewPassword.ps1
. $psScriptRoot\SelectItemByAclEntry.ps1

the dot sourcing means load the file and keep the functions in memory.  That way I can keep major functions in their own files for ease of management.

The in my profile I use:
Import-Module PBCPSModule

PowerShell will look in the Module directories under the user hive and under the install directory for a directory called PBCPSModule and in there for the file PBCPSModule.psm1 which it will then execute.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes