0%

0/1 Lessons

Course Introduction

• 5min

0 / 2 lessons complete

Getting Started with Windows PowerShell

• 56min

0 / 8 lessons complete

Getting Help and Finding Commands

• 39min

0 / 6 lessons complete

PowerShell Command Syntax

• 33min

0 / 5 lessons complete

PowerShell Objects and Properties

• 35min

0 / 6 lessons complete

The PowerShell Pipeline

• 24min

0 / 2 lessons complete

PowerShell Providers

• 30min

0 / 5 lessons complete

PowerShell Arrays and Variables

• 28min

0 / 4 lessons complete

PowerShell Loops

• 19min

0 / 3 lessons complete

PowerShell Conditional Statements

• 11min

0 / 1 lessons complete

On Premises Lab Setup

• 36min

0 / 8 lessons complete

Basic Domain Administration with Windows PowerShell

• 2hr 27min

0 / 10 lessons complete

Send Emails with PowerShell

• 22min

0 / 2 lessons complete

PowerShell Desired State Configuration (DSC) Basics

• 1hr 48min

0 / 6 lessons complete

PowerShell Modules

• 58min

0 / 7 lessons complete

Powershell Challenges

• 1hr 55min

0 / 23 lessons complete

Course Conclusion

• 1min

0 / 1 lessons complete

Creating the PSM1 PowerShell Module File

Instructions

Q&A (0)

Notes (0)

Resources (0)

Saving Progress...

Resources

There are no resources for this lesson.

Notes can be saved and accessed anywhere in the course. They also double as bookmarks so you can quickly review important lesson material.

Create note

Expand the full completed source code for this lesson below:

GreetMe.psm1 Full Source Code

In this lesson, we're going to be writing our PowerShell module or PSM1 file. Now, in this particular instance, what we're going to do is define a couple variables at the top. So I'll just call this variables. We're going to import all private functions. Then we're going to import And export functions from the public folder, and we're going to do this dynamically.

Now I want to make a note about security. What we're going to do for development purposes is automatically import any PowerShell files that are in the new public or private folders. And what this means is if somebody gains access to your system and they put. A file in here, a PowerShell script that has malicious code.

Your function will automatically import and execute that. And you may think, you know, that's not very good and it's really not. But I would also argue if somebody has permission to create files and PowerShell scripts and place them on your file system, you're already in a lot of trouble. With that being said, the system that we're going to write that will automatically dot source all of these PowerShell scripts can easily replace once you're done writing your PowerShell module. By just manually calling out each file that we have inside of here again, if someone can write to your file system, they could just open up this module file and manually import or include those PowerShell files that are malicious as well that they can just place in the file system, so, I don't really think you're mitigating much, and I've seen several other modules that use the same method, but I want you to be aware that you know, this is, this could be a vulnerability, but we're going to go ahead and just do this because it's going to save us a lot of time, and I don't think it's a big deal for our lab exercises.

All right that's between you and your security team if you want to do this or you want to go a different path. So I'm going to make, create a couple of variables here at the top, and this is going to be our module public path, and this is going to be equal to, we're going to use join dash path, and we're going to use ps script root.

And then we're going to join it with public. Alright, so we're taking this variable pscryptr, which if I execute right now, will probably be empty. Now this is a tricky variable that is reserved it's, or it's a default variable that is, will be present when we say import module. This will, this variable will be populated, but when we just run it in our terminal, it's empty.

Okay. So I just want you to be aware of that, but what this is going to look like is it's going to be this full path and we're going to take this and we're going to join this with public. So just to give you an idea of what that's going to look like, if I copy this and I say, join dash path and I paste in that, and then I paste in public, this is what we end up with.

See users, administrator documents, PowerShell modules, greet me, which is the folder that we're in right here at the top and then the folder public. Okay. Now. I'm going to copy this line in the way that I like to do this in Visual Studio code is by holding shift and alt and press the down arrow and look at that.

Server Academy Members Only

Sorry, this lesson is only available to Server Academy Full Access members. Become a Full-Access Member now and you’ll get instant access to all of our courses.

0 0 votes
Lesson Rating
Subscribe
Notify of
profile avatar
0 Comments
Inline Feedbacks
View all comments