Installing PowerShell Modules With PDQ Deploy

Purpose

You want to install PowerShell modules in your environment using PDQ Deploy.

Resolution

Installing PowerShell modules means doing so from a repository.  That repository can be internal or external like the PowerShell GalleryWhile modules published to the gallery are typically safe make sure that you thoroughly vet modules before you download them!

  1. Download Install and Import Module.ps1 and place it in your Deploy repository.
  2. Create a new Package with a PowerShell step and click the "Insert PowerShell Script" button.mceclip1.png
  3. Navigate to the script location and select it.  Your PowerShell panel should now look like this:mceclip2.png
  4. Now that we have our script ready to go all we need to do is add our arguments.  The script takes one mandatory and one optional argument.  The “ModuleName” parameter is required and is where you can enter the name of any module in the PSGallery.  There is also an optional "scope" parameter that tells the script if you want to install the module for the current user or for all users of the machine.  The default value is "CurrentUser" to ensure we're only installing modules for the PDQ Deploy account.mceclip3.png

Much of the time the modules will only need to be used by your Deploy account as that is the account that most often runs deployments.  If you want to install modules for other users on the computer you have three options.

  1. To install a module for the currently logged-on user ensure that the user is logged onto the computer. Set the Run-As user in on your package to “Logged On User”.  When Deployed the package will now install for the currently logged-on user.mceclip1.png
  1. Add the -Scope parameter to your PowerShell call and set the value to ‘AllUsers’.  The caveat to this method is that the module will now be installed for everyone on the machine.  While the scope of what a non-admin user can do with PowerShell is limited ensure you understand the power you’re giving your users.mceclip2.png
  1. You can also simply copy the module files to the user’s machine with a copy step. You will first need to save the module to a location where it can be copied from.  You can do this using the Save-Module cmdlet.
Save-Module -Name pswindowsupdate -Path <Insert path to save to>

 This will save the module to the location you pass to the path parameter.  After saving the module you can simply create a package with a copy step and copy the module to the user’s module path.  This  path is <Path to user folder>\Documents\WindowsPowerShell\Modules\ .  Install-Module is preferred to this method as on occasion there can be some difficulty uninstalling modules that were copied into place rather than installed.

 

Was this article helpful?
Still have a question or want to share what you have learned? Visit our Community Discord to get help and collaborate with others.