This blog post tells you where to install PowerShell modules. Not long ago, I was working with PowerShell (PS) in order to create a few automation scripts. This was a bit of a challenge for me as I’m still learning PowerShell. I was working on a protected network, with no internet access, and trying to apply software updates (SUs). I soon discovered that, at a high level, I needed to perform the following tasks and each section would become its own PowerShell script:
1. Create a list of SUs that need to be deployed.
2. Synchronize a WSUS server that has internet access with Microsoft.
3. Perform a WSUS clean-up.
4. Approve all required SUs.
5. Download those SUs to the WSUS content directory.
6. Export the WSUS database.
7. Copy the WSUS database and the WSUS content directory to the protected network.
8. Import the WSUS database.
9. Ensure that the SUs are copied to the right folder.
10. Deploy the SUs.
This might not seem like a lot of work, but it is. Who wants to manually approve 20+ SUs each month? Let alone manually approving 400+ SUs the first time you sync the WSUS database?
You might be asking at this point, what does this have to do with PowerShell modules? You can use PowerShell scripts to help you automate a lot of tasks. For example, I ran across this helpful module/script, PoshWSUS, which I will use to automate WSUS tasks.
While researching PoshWSUS, I read a blog post by Boe Prox.
In the section entitled, “Initial use of PoshWSUS,” he writes:
To download the module, see PoshWSUS in CodePlex. Unzip the files to your Modules directory—in my case for Windows 7, it is C:\Users\Boe\Documents\WindowsPowerShell\Modules. I saved the modules to a folder named PoshWSUS. This location is shown here.
I took the PoshWSUS module/scripts and created the directory structure suggested by Boe. I also edited the path for my username. Needless-to-say it didn’t work for me, so I did some more research on how to import a PowerShell module and I didn’t find anything useful. Finally, I stumbled across a PowerShell command that tells you where your modules should be located. The PowerShell command is:
I ran the command and reviewed the results.
The directory that Boe suggested to use for the module location is listed within the path, but there was also a Program Files location. Since the Program Files location directory would allow anyone on the computer to run the module/scripts without any problems, I copied the PoSHWSUS module there instead. Ultimately, using the Program Files location saves me time later on too.
Afterwards, everything worked as I expected.
The long and short of this blog post is:
If you are looking for where to install PowerShell modules, use the PS command ($Env:PSModulePath) to locate the correct path.
As for my WSUS export script, it is still a work in progress, but you should see a blog post about it soon.