Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I run powershell commands without installing module?

Tags:

powershell

I would like to run a script that requires to use commands from the GroupPolicy module. However, this module is not guaranteed to be installed on every machine and some machines might be stand alone. Can I have have the module copied over with my scripts and run commands from it, without installing the module?

like image 330
boblewis Avatar asked Nov 23 '25 11:11

boblewis


1 Answers

Can I have have the module copied over with my scripts and run commands from it, without installing the module?

Yes. Installing a module in PowerShell simply means placing it one of the directories listed in the $env:PSModulePath environment variable, which allows PowerShell to discover it and import (load) it on demand, as part of the module auto-loading feature

However, you're free to copy modules elsewhere, as long as the code that relies on them knows their path and loads them with an explicit Import-Module call.

For instance, if you bundle your script with a GroupPolicy subdirectory containing that module, the script could import it as follows:

# $PSScriptRoot contains the calling script's directory.
Import-Module $PSScriptRoot\GroupPolicy
like image 158
mklement0 Avatar answered Nov 26 '25 17:11

mklement0