Monday, April 29, 2024
HomePowershellModule Linking • The Lonely Administrator

Module Linking • The Lonely Administrator


I do know it has been some time since I’ve given the weblog any consideration. I hope to right that in 2024, though I am already not on time. However let’s get to it.

I’ve a brief tip at this time that you could be discover helpful, particularly when you write modules on your personal use. I’ve various such modules that I’ve written to fill my wants. These are personal modules that I do not publish to the PowerShell Gallery. I develop and keep these modules in C:Scripts. Because of this once I must import the module, I’ve to sort the complete path.

Import-Module -Title C:ScriptsMyModule.psd1

Granted, I load many of those modules in my PowerShell profile script. However it could be nicer to have PowerShell auto-import them because it does different modules.

PSModulePath

The auto-import works as a result of most modules are put in in a listing that’s listed within the $env:PSModulePath setting variable. This variable is a listing of directories the place PowerShell appears for modules.

PS C:> $env:PSModulePath -split ";"
C:UsersJeffDocumentsPowerShellModules
C:Program FilesPowerShellModules
c:program filespowershell7Modules
C:Program FilesWindowsPowerShellModules
C:WINDOWSsystem32WindowsPowerShellv1.0Modules
C:Program Information (x86)Microsoft SQL Server150ToolsPowerShellModules

I may modify this variable to incorporate my C:Scripts listing, however I do not need to try this. That might add modules which can be really in improvement and never prepared for normal use.

As a substitute, I can create a symbolic hyperlink to the module in one of many directories listed in $env:PSModulePath. I can do that with the New-Merchandise cmdlet.

I’ve a PowerShell 7 module I take advantage of to handle my Stripe account. I keep this module in C:ScriptsStripeTools. As a substitute of manually importing the module, it could be nicer to have it auto-imported. I can create a symbolic hyperlink to the module within the C:Program FilesPowerShellModules listing.

New-Merchandise -Path "c:program filesPowershellModules" -Title StripeTools -ItemType SymbolicLink -Worth C:scriptsStripeTools

It’s that easy. I can proceed to take care of the module in C:Scripts the place information are routinely backed up. However I can use the module like every other. In fact, if I am in the midst of updating one thing, I will be utilizing the module in it present state. However that is on me, and actually is not that a lot totally different than what I face now.

What is absolutely attention-grabbing, is that C:Scripts is itself a pointer a folder on OneDrive. This retains my information backed as much as the cloud and synchronized throughout my units. After I import my linked module, I am truly utilizing information from my OneDrive folder. This can be a massive win all the way in which round.



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments