Avatar of KC2TC
KC2TCFlag 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
ASKER CERTIFIED SOLUTION
Avatar of Gary Dewrell
Gary Dewrell
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Brent Challis
Brent Challis
Flag of Australia image

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.
Powershell
Powershell

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.

27K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo