PowerShell Module 5: Creating Custom PowerShell Modules

  Рет қаралды 18,903

Bryan Cafferky

Bryan Cafferky

Күн бұрын

Пікірлер: 50
@LagunaDaeron
@LagunaDaeron 3 жыл бұрын
3 years later and this is still highly relevant. Thanks for the info!
@BryanCafferky
@BryanCafferky 3 жыл бұрын
YW
@TheJeremyMorel
@TheJeremyMorel 6 жыл бұрын
Hi Bryan - Stumbled across this video and wanted to express appreciation. I'm a OOP coder who's well-versed with PowerShell, but never took the time to learn modules, manifests, and the like the right way. This was an awesome way to "cheat" myself back into compliance! Also, importing as a custom object is an awesome crutch for me to feel better about the inherent sloppiness of scripting! Thanks!!
@BryanCafferky
@BryanCafferky 6 жыл бұрын
Glad it helped. Thanks
@BryanCafferky
@BryanCafferky 6 жыл бұрын
Hi Jeremy, Thanks. Yeah. It is a quick and easy way to do OOP. PowerShell does now support True classes and inheritance but I like the ease of this method of getting the same effect.
@madcasekc595
@madcasekc595 Жыл бұрын
I don't think anyone explains this better. Excellent tutorial!
@AhmedAli-dz1hy
@AhmedAli-dz1hy 3 жыл бұрын
Thank you Bryan from Saudi Arabia. Great lecture
@BryanCafferky
@BryanCafferky 3 жыл бұрын
You're welcome. Thanks for watching.
@Noviticus
@Noviticus 3 жыл бұрын
Thanks for all the info, still after 2 years still relevant.
@BryanCafferky
@BryanCafferky 3 жыл бұрын
YW
@beelim7963
@beelim7963 4 жыл бұрын
Love all these little valuable tricks that you're teaching us. Thanks so much!
@BryanCafferky
@BryanCafferky 4 жыл бұрын
Glad they help. Yeah. PowerShell has some very cool tricks.
@eespiedrop2
@eespiedrop2 3 жыл бұрын
A brilliant video. Thanks for taking the time to produce and post this.
@BryanCafferky
@BryanCafferky 3 жыл бұрын
YW. Glad it helps.
@akensturgeon
@akensturgeon 5 жыл бұрын
Thanks for the Powershell series Bryan; this was VERY helpful.
@alex17texas
@alex17texas 5 жыл бұрын
This video has great info. Exactly what I needed. Cheers from Colorado!
@mav29
@mav29 2 жыл бұрын
perfect, as I was trying to do same approach @ 3:50 spot on.... 5:58 it is indeed a library or atleast the way I try to do it that way too breaking it down. I am really happy I stumbled upon this video as I just started doing babysteps towards powershell although I do have small background on programming, going through the video feels like I'm just about to get in to the good part thx thx
@Dayison
@Dayison 3 жыл бұрын
Very much appreciate this! Thank you!
@BryanCafferky
@BryanCafferky 3 жыл бұрын
You're welcome.
@michalpardej5577
@michalpardej5577 6 жыл бұрын
That was a good and helpful video, thanks!
@BryanCafferky
@BryanCafferky 6 жыл бұрын
Thanks! Glad you got something from it.
@didier_lu
@didier_lu 6 жыл бұрын
HI, thank you so much. Great, great tutorial!
@BryanCafferky
@BryanCafferky 6 жыл бұрын
Thanks!
@khanhvu90
@khanhvu90 5 жыл бұрын
Great tutorial!! Thank you.
@BryanCafferky
@BryanCafferky 5 жыл бұрын
Thanks!
@mikaelbackstrom
@mikaelbackstrom 4 жыл бұрын
I really love the simplicity of maintaining code with the dot sourcing, but my experience is that when I do a Remove-Module does not take the loaded functions into consideration. I have no idea how that would effect performance with time?
@BryanCafferky
@BryanCafferky 4 жыл бұрын
Script modules are a better approach than dot sourcing in most cases as it provides easier code maintenance and code sharability. However, you can remove functions not loaded via module too. See powershell-guru.com/powershell-tip-35-list-and-remove-a-function/
@johnwells7197
@johnwells7197 5 жыл бұрын
Great stuff! I have the book and about to attack it.
@Putteblaze
@Putteblaze 4 жыл бұрын
In my PS modules, i always throw in the .psd1 and also have that dot sourcing! Or import-module instead of . (Never checked if there are any difference part from been run.. gotta do that i guess 😓)
@skycoolmiles1835
@skycoolmiles1835 4 жыл бұрын
Hi Brian. Great video on PS modules btw. Do you offer any one to one online teachings? Thanks. Nile
@BryanCafferky
@BryanCafferky 4 жыл бұрын
Great idea. What are you interested in understanding?
@timothywestern6488
@timothywestern6488 4 жыл бұрын
The only thing I did not get. was the 'maintainability' as files argument. Wouldn't source control be so much easier?
@BryanCafferky
@BryanCafferky 4 жыл бұрын
I agree. Definitely use source code control. The problem is when a function has been duplicated multiple times, in separate scripts, there is more work to maintain the code. In PowerShell, there is a tendency to write many one-off utility scripts, perhaps with slight differences or even hard-coded values, rather than extracting them to functions and putting them in a module. Thanks
@timothywestern6488
@timothywestern6488 4 жыл бұрын
@@BryanCafferky oh yeah believe me I've bit my ownself in the but many times because I didn't think more than one off with a script or two... or more.
@GeekMustHave
@GeekMustHave 5 жыл бұрын
I owe you a beer, may two. You saved me so much time. You are an excellent instructor. Where can I find the udm_utility.psm1? Keep broadcasting!!
@BryanCafferky
@BryanCafferky 5 жыл бұрын
Glad it helped. The code can be found at: github.com/bcafferky/shared/tree/master/PowerShellModules . Just download and unzip the file.
@saitt6582
@saitt6582 4 жыл бұрын
In my powershell file First.ps1 i have a Function Sum. In the Second.psm1 module i have the Functions: Sum, Multiply. How to only Import Multiply into First.ps1.
@BryanCafferky
@BryanCafferky 4 жыл бұрын
You can use the -FUNCTION parameter of the Import-Module cmdlet. See docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Core/Import-Module?view=powershell-7
@ronjennings7533
@ronjennings7533 5 жыл бұрын
This isn't working for me. I created the module (.psm1) file exactly like yours, and I have one .ps1 file in my function directory, but when I import the module it doesn't import the function. Am I correct in understanding that a .psm1 file is basically just a script that runs when you import the module?
@ronjennings7533
@ronjennings7533 5 жыл бұрын
I got it working by changing the path concatenation in my loop to this: #Loop through the list of files and load them foreach ($function in $functionList) { $fullPath = $functionDirectory + $function Write-Host 'Importing file: ' $fullPath . $fullPath } For some reason it wasn't liking {$functionDirectory + $function}
@BryanCafferky
@BryanCafferky 5 жыл бұрын
Did you put the module in your documents\WindowsPowerShell\Modules folder? That is usually a default location where it will look for modules.
@nabeel221568
@nabeel221568 5 жыл бұрын
@@BryanCafferky - $PSScriptroot is empty for me! I am working on ISE and whenever I tried Importing custom Module, nothing happens?
@nabeel221568
@nabeel221568 5 жыл бұрын
Also lets say if I upload the Module in powershell gallery? Will the .psm1 concept of calling function will work??
@Putteblaze
@Putteblaze 4 жыл бұрын
Nabeel Zaidi if you run the saved script with the $PSScriptRoot you will get the folder path, you cannot run it in other way. 1. Saved as file. 2. Script is run or in debugging mode, mostly no other way.. i’m just 7months late to answer.. sorry 😅✌️
@iswatibaranwal
@iswatibaranwal 6 жыл бұрын
Show-command not working in my system, any specific reason for that and how to fix it?
@BryanCafferky
@BryanCafferky 6 жыл бұрын
Check your PowerShell version by entering $PSVersionTable.PSVersion
@mahosho5084
@mahosho5084 2 жыл бұрын
The organizations entire group now has to cleanup a deceiving install of several PCs
@BryanCafferky
@BryanCafferky 2 жыл бұрын
What is this comment referring to?
PowerShell: Writing  Functions
33:11
Bryan Cafferky
Рет қаралды 42 М.
PowerShell Module 1: An Introduction to the CLI and ISE
33:16
Bryan Cafferky
Рет қаралды 16 М.
Мясо вегана? 🧐 @Whatthefshow
01:01
История одного вокалиста
Рет қаралды 7 МЛН
Mom Hack for Cooking Solo with a Little One! 🍳👶
00:15
5-Minute Crafts HOUSE
Рет қаралды 23 МЛН
PowerShell Master Class - Connecting Commands Together
1:06:50
John Savill's Technical Training
Рет қаралды 109 М.
PowerShell Scripts
49:37
TechThoughts
Рет қаралды 84 М.
Introduction to PowerShell Module 3: Loops
36:40
Bryan Cafferky
Рет қаралды 14 М.
Developing with PowerShell Classes: Here be Dragons by Brandon Olin
44:40
What to Learn for Your Career Path
16:53
Bryan Cafferky
Рет қаралды 2,1 М.
Мясо вегана? 🧐 @Whatthefshow
01:01
История одного вокалиста
Рет қаралды 7 МЛН