Whenever I switch to a new computer, I frequently launch PowerShell, run a cmdlet, and the screen barfs red text to let me know that the cmdlet isn’t recognized. Which quickly reminds me that I’m an idiot and forgot to install the modules to my new system. Enter this blog post!
While I often keep PowerShell notes/tips in my OneNote notebook, I thought it would be useful for others to share here. There are many great blog posts already about setting up PowerShell, but I don’t recall seeing one that includes all of the “gotchas” that come with setting up a new system. Hopefully I’ve caught them here.
If you’re on a Windows machine, you should already have some basic modules, but how do you know for sure? Launch PowerShell (always run as administrator) and type:
Get-Module -ListAvailable
You should see a “laundry list” of the available PowerShell modules, which at this point, are primarily the ones installed by default with PowerShell. So with all these modules, why do you need anymore? There are thousands of different PowerShell modules out there that serve different purposes. For example, the ones I use regularly are MSOnline, ExchangeOnlineManagement, MicrosoftTeams and AzureADPreview for Microsoft 365 (M365) administration.
So how do you get these modules? First, it’s good to know where they come from, which is usually the PowerShell Gallery. The easiest way to install a new module is through PowerShell itself. Microsoft has some documentation on Getting Started with the PowerShell Gallery, but skipping to the good part – here’s the info on how to install a module:
“Install-Module installs the module to $env:ProgramFiles\WindowsPowerShell\Modules by default. This requires an administrator account.”
The catch: before you can use Install-Module to install modules from the PowerShell Gallery, you must first install the PowerShellGet module. Another catch: you need to install the NuGet Provider before you can get PowerShellGet (get it?). Remember to run your PowerShell session as an administrator:
Install-PackageProvider -Name NuGet -Force
Install-Module -Name PowerShellGet -Force
And one more catch: if Install-PackageProvider throws an error, it may mean that your system is not running the latest version of TLS, which will need to be installed. Ali Tajran has a great post on how to resolve this issue, so please see his post if you need to check/update TLS.
FINALLY your system is ready to install some modules! Search the PowerShell Gallery to find the modules that you need to wield the power of PowerShell!