Finding and installing PowerShell modules
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.
 In this lesson, I'm going to be showing you how to install PowerShell modules. Now, when you're working with PowerShell, it can be helpful to install PowerShell modules, which will increase your efficiency and just make life easier when you're starting to work with PowerShell, we're going to cover a couple of different ways to install PowerShell modules that would be through the install dash module, we'll talk about fine dash module, as well as using the PowerShell gallery in your web browser, doing things like installing modules directly from GitHub, and just manually putting modules inside of your modules folder in PowerShell. We'll finish up by uninstalling modules, and then that'll be it for this lecture.
Alright, so to get started, what I'm going to do is start with the find module command. If I say find module. And just press enter. For example, what's going to happen is it's going to start outputting all of the modules that I have in my current PowerShell repository, and I'm just going to hit control C because I think at the time of this writing, there's 11 or 12 thousand packages available and you'll notice there all from this repository PowerShell gallery.
So we have speculation control P S one is update. All of these are from P S gallery, which is our only repository that we have installed by default. And I can see that by saying get dash P S repository. If I press enter again, I'm hitting tab to auto complete that in case you're wondering if I press enter, it's going to tell me that the P S repository that I have installed is PowerShell gallery.
And it's untrusted, which means if I try to install one of these modules, I'm gonna get a pop up saying, Hey, you don't trust this repository. Are you sure you want to install this module? And of course, we'll probably say yes, but it also tells me the source location. Now, you may be wondering when are you ever going to add a different repository?
That would be when you maybe have a offline repository maybe at work, you have an enterprise with custom modules. You may need to add that or register that here. If I run get command and pipe that to the greatest PowerShell command ever, which I consider to be OGV, which is Out-GridView, that gives me every command I have available to me.
I can do all kinds of cool stuff like filter. So if I say repository, Here are all the commands that we have that around getting a repository. So we can register a new PowerShell repository, set one, unregister, and get, which is the command that we just ran. Okay, now while we're here, let's just go ahead and take a look at modules.
So if I search PowerShell get, Here are all the commands that we have. We have find module, which is what we just used. We have install module. We have save module, which will actually just download the files. And then we have uninstall module.
Also, update module, this will update any installed module that we have. These are the ones that we're going to be working on today. So, go ahead and close this. Now, if we want to filter our modules in this example, or this lesson, we're going to use the module PS dates. And if I wanted to find something that would help me work with dates, I could just specify the tag argument and say date.
And I want to give you a quick tip real quick. If I'm not sure what arguments or what parameters… That I can pass to this, I can press the dash key on my keyboard and then hold left control and press space bar. And what this is going to do is show me all the parameters available for this command!
and I can use the arrow key to move around and select a specific option. Now in the cyan color here at the bottom, right here, this is actually telling me what I need to pass to this parameter, so it tells me the type of object what we're looking for is tag and here I can see I can pass an array of strings.
Alright, so if I press enter, it'll put that in for me and I'm going to pass a string which would be date. And I'll press enter. So I'm saying find module date. Now here we see the first one that I'm looking for is the one that I'm going to be installing here. The first on the list. Rather, it is PS dates.
If I wanted to see more information about this, I could say. Format list and press enter, and this is going to dump out everything that we just looked at, which is in my opinion, way too much information. So instead of searching by tag, I'm going to press the up arrow to get that command back. And I like to do as many shortcuts as I can.
I'll try and explain them to you. I'm going to hold control and hit the left arrow to skip words. So you'll notice instead of having to tap it several times like this. If I hold ctrl and hit right arrow, left arrow, it skips over whole blocks of words. It's a really quick way to get around your the command that you're typing.
So instead of doing dash tag, I'm going to delete this. I'm going to hit ctrl space, and I'm looking for name, which is the first one on the list. And the name is going to be psdates with an s. All right, I'll press enter and that's going to format that as a list. So this will only be the PowerShell dates and I have more information about this.
So I can see the name, the version type here's a full description. You'll notice it's not concatenated or shortened. I should say truncated is probably the right word. I can see the author and the company name as well as the website for this guy. So if I click copy this project, you are I, and I hit left control.
You'll see. I can open my browser and I already had it open, but this is the actual page. This is the GitHub page where I can see when it was last updated, kind of old, three years old probably older by the time you watch it. So keep that in mind. But it gives examples and, and different kinds of information like that.
Also we can which we'll be talking about in a little bit later, but we can download the actual source code if we wanted to. But switching back over to PowerShell. This is how we can kind of get information about. The different modules that we might want to install. So what we're going to do is go ahead and install that module.
We're going to do this with the install module command. And we're going to say dash. And again, if you want, you can use the little shortcut control space. And we'll use name. I'm pressing enter to auto populate that, or to type it for me. And inside of quotation marks, I'm going to do psdates. And I'll press enter.
Now, because the repository is not trusted, it's going to say, Hey, this is an untrusted repository. If you want, you can change these settings so that you trust the PS gallery by default again. This is the default PowerShell repository that everybody has installed. I'm just going to go ahead and just leave it like it is, but I'll press why and I'll say yes, I trusted that allows me to install the module PS dates.
If I type get dash module, it will not be listed there yet, and that's because I just installed it and I haven't imported it yet. So if I run import dash module. PS dates and then press the up arrow two times to get back to my get module. If I press enter now, you'll see that whereas before it was not listed under.
After PowerShell get. After PowerShell get, I now have PSS dates. If I wanna see all the commands that are available to me from this module, I can say get dash command. And I'll use my little shortcut. And what I'm looking for is module. If I start typing in module, it'll auto-populate or filter down the list, which is kind of a cool thing.
So like, if I type E. it filters that list to everything with an E in it. So if, and it is just the first letter. So for example, module has an O and so does noun. And so does command. But if I type O, it's only going to show the ones that start with O. Okay. So that's one thing to keep in mind.
But anyways, again, we're saying module I'll press enter and the modules PS dates and I'll press enter. And this gives me all the functions that I have available to me from the source PS dates or the module PS dates. So if any of these look like they'd be useful for whatever project that I'm working on that could really save me a lot of time.
Okay, so that's one way to install modules. Another way to do it is to go directly to the PowerShell gallery in your browser. So I can type in PowerShell gallery. And this is going to open the PowerShell gallery. Here we can see the total number of packages, which is how many packages that were going to be listed when I said find module.
So that's a ton. So if I want to search for the same thing, I can just type in date. And the first thing, we're getting actually a bunch of things that we're not looking for, like, PowerShell windows update because date is in the, the string. I think if I wrap this in quotes, It will be a little more strict.
And again, we have PS dates here at the top. This is the one that we just installed. So this gives us the command that we, that we actually ran earlier. So you can click this and it'll copy it to your clipboard. You can go to PowerShell and let me copy that again. Right click and paste it in there and then I can install the module just like that.
So this is another method that we have to do this. Now, let's go ahead and uninstall this module. To do this, what we're going to use is the uninstall module command, and the name is going to be psdates. So, uninstall module. Just like before, and the name is going to PS dates. Now, this is probably not going to work because we have this module imported.
So I'm expecting it to throw an error. So it's saying it's currently in use. What we need to do is close PowerShell and relaunch it as an administrator because we can't have an open session that's using the module when we try to uninstall it.
So I'm going to go ahead and right click and say run as administrator and I'll maximize this screen and I'm going to press the up arrow because it still remembers the last command that I ran so I don't have to retype it. And now I'm going to press enter and it's going to say uninstall module name psdates.
And it's thinking it's probably uninstalling it, hopefully. So we're just going to wait a second. Now it looks like it's done. So what I'm gonna do is say, get dash module. And now we don't have PS dates listed here anymore.
So that leads us to our next point. How do we install things manually? Or better yet, when we're creating our own modules, there's a way that we're going to have to do that without installing it from the PowerShell gallery because if you're creating your own custom module. It's not going to be in the PowerShell gallery.
So now I'm going to install it manually by copying the zip file directly into our PowerShell modules directory. And so what I'm gonna do is download it from GitHub. I'm going to go back to find dash module and I'm say dash name and dash name is going to be PS dates. And I'm going to format that as a list or pipe that to FL or format dash list, not table.
I always like to use table, but that's not actually what I want to use here. Now if I wait, this is going to give me the information about that, including the GitHub link under the site URL. So project URI, if I double click this, I can hit left control C to copy it, go to my browser and paste that URL in here at the top.
And now what I'm going to do is click download zip. All right, now I have that zip file downloaded. What I'm going to do is go ahead and open the zip file. I'm going to actually go back to downloads. I'm going to hit extract all. And I'm going to extract this into this folder. That's perfectly fine. But what I'm going to want to do is refresh this so I can see the, the extracted folder in here.
And it's trying to be helpful by opening it. That's not really what I wanted to do. I'm going to open this directory and I'm going to hit F2, select it and hit F2 and get rid of dash master master. GitHub. It's just something that GitHub likes to do. It likes to add it to the folder name so you know what branch you're on.
So if I click this here, you can see, well, there's only one branch master, but normally there'll be several branches like development, master, maybe production, and then branches for different fixes or patches that they might be trying to work on. And that's always added to the folder when you download it from GitHub.
So we want to remove that because that's going to mess it up when we try to import it into PowerShell. All right. So now that we have this folder downloaded, we need to figure out where we're going to put it and PowerShell will tell you if we do environment to get our environment variables and do a colon, we can do a PS module and I hit tab.
It'll autocomplete PS module path. If I press enter, it's going to give me all the module paths that I can use to just drag files or drag custom modules into. All right. This is where we're going to put the actual module files to manually install a module.
This is kind of hard to read because it's separated by the semicolon. So what I'd like to do is wrap this inside of parentheses and say dot split. And we're going to split it by this semicolon because that's what I can see it's, it's separated by. If I press enter, this will change it so that it's put on one line.
So I have this one, which is my home directory. This is my, I'm currently logged in as administrator. So see user's administrator. This is my home user directory. I could use any of these other ones, but like this one will require administrative privileges, which can be difficult depending on where you are.
If you're at your workplace, it might not be a good idea. . And this is under C Windows System 32, which is not probably where you want to be messing around. So I'm going to use the first path. So I'm just going to select this left control C, and I'm going to open a Windows Explorer, navigate to that directory.
And of course, it thinks it can't find it because the modules directory folder doesn't actually exist. So back in PowerShell, I'm going to say, make directory. And just before I do this, I want to make sure I'm not going too fast and I'm explaining what's happening. The modules folder doesn't actually exist.
So if I go to Windows PowerShell, there's no modules folder in here. And that's why that's throwing a fit. This is, it is looking for the modules folder, but it doesn't exist yet. So I'm going to run the M K D I R command or make directory command. And I'm going to create that modules folder. So I'll press enter.
All right. And if I go back to windows Explorer, now I have the modules folder that it was looking for. So inside of this folder, I'm going to go to PS dates dash master, and I'm going to drag this folder into my modules folder. Alright, so now I have the folder PSDates inside of my Windows Modules folder.
So again, this is the full path C, Users, My Username, which is Administrator, Documents, Windows PowerShell, Modules, and then the module folder name is PSDates, which matches the PSDates. psn1 file. This is a requirement. If that still was PSDates Master, it probably will not work when you try to import the module.
Alright, so now that we have that done, I'm going to go ahead and CLS to clear the screen and I'm going to say import module ps dates and I'll press enter and it's kind of throwing a fit here because the script is not digitally signed and my execution policy is not allowing me to do this. So what I have to do is say set execution policy. And I'll say control space. I'll say unrestricted, for example. And this is going to allow me to run scripts, even if they're not signed.
And I'm going to say A for yes to all. When it asks me, are you sure you want to do this? Cause it's not really a great security practice to do this. But we need to be able to run this script. So we're going to do that. Now that I've done that, I'm going to clear the screen. So again, if you're not, if you're still trying to type that, I'll just wait a second, set dash execution policy.
And that is going to be unrestricted. And then when you get the prompt, we're going to say a for that equals. Yes to all. So I'll clear the screen with CLS.
When we try to import the module PS dates on my system, it's saying, hey, I don't trust this script so it's going to ask me for each one of these scripts inside of the PowerShell module.
So what I'm going to say is left control C to cancel this, and we're going to use what it recommends is the unblock file commandlet. So what I need to do is go to this module folder and just copy it. This is where we extracted PSDates. And if I do get child item and say dash recurse and paste in that directory.
What I'm going to want to do is run the unblock file commandlet against every file in this directory, which is going to be a royal pain if we try to do this manually.
But, thankfully, PowerShell makes that pretty easy. So I'm going to press the up arrow and just pipe that to unblock file. And I'll press enter. So now all the files… That's all the ones that we just output here have been unblocked. So if I say import module and I import psdates, I should be able to do that now.
So now I don't have any more errors. So this is on Windows Server 2022. They're kind of up in the security game. If you don't have these error messages or problems, don't worry about it. You're good to go. But if I do get module now, now I have psdates. And I have the same functionality that I had before when I manually installed it.
Now if I try to uninstall dash module and I do PSS dates it, we're gonna have an issue. And what we're gonna see is it will say that no match was found for the specified search criteria. Module names, PSS dates. It's saying it's acting like it's not installed. And this is because we didn't install it with, I install dash module, so we cannot uninstall it with uninstalled dash module.
What we have to do. Great. So now I'm going to go to the directory, go back, go module is, and hit Delete. Now, this isn't going to let me do it because it's in use. Remember when we tried to use uninstall module and it failed? That's because our PowerShell session was still open. So what I need to do is close my PowerShell session, hit Try again, and now I can delete the PowerShell module.
Alright, just a little recap. We use the find dash module command lit to find the modules. We search by tag. We use control space to quickly find what parameters we can specify or pass to our commandlets. we use install dash module to install the module uninstall module uninstalled dash module to uninstall the module.
And we downloaded the package and then we looked at browsing the PowerShell gallery to copy the install commands and we learned how to go to GitHub, download the PowerShell module and how to manually install it in our PowerShell modules folder. All right, that's all we had to cover in this lecture.
Great job getting through this one and I look forward to seeing you in the next lecture.