11--- 
22description : Explains how to install, import, and use PowerShell modules. 
33Locale : en-US 
4- ms.date : 08 /09/2024
4+ ms.date : 10 /09/2024
55online version : https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_modules?view=powershell-5.1&WT.mc_id=ps-gethelp 
66schema : 2.0.0 
77title : about_Modules 
@@ -18,29 +18,24 @@ PowerShell are implemented as scripts, functions, or cmdlets. The language
1818includes [ keywords] [ 07 ] , which provide the structure and logic of processing,
1919and other resources, such as variables, providers, aliases.
2020
21- A module is a self-contained, reusable unit that can include cmdlets, providers,
22- functions, variables, and other resources that can be imported into a PowerShell
23- session or any custom PowerShell program.
24- 
25- Before the functionality contained in a module is usable, the module must be
26- loaded into the PowerShell session. By default, PowerShell automatically loads
27- an installed module the first time you use a command from the module. You can
28- configure automatic module loading behavior using the variable
29- ` $PSModuleAutoloadingPreference ` . For more information, see
21+ A module is a self-contained, reusable unit that can include cmdlets,
22+ providers, functions, variables, and other resources. By default, PowerShell
23+ automatically loads an installed module the first time you use a command from
24+ the module. You can configure automatic module loading behavior using the
25+ variable ` $PSModuleAutoloadingPreference ` . For more information, see
3026[ about_Preference_Variables] [ 08 ] .
3127
32- You can also manually unload  or reload  modules during a PowerShell session. To
33- unload  a module, use the  ` Remove -Module`  cmdlet . To load or reload  a module,
34- use  ` Import -Module` .
28+ You can also manually load  or unload  modules during a PowerShell session. To
29+ load or reload  a module, use ` Import -Module` . To unload  a module, use the 
30+ ` Remove -Module`  cmdlet .
3531
36- PowerShell comes with a base set of modules. Anyone can create new PowerShell
37- commands or other resources, and publish them as modules that users can install
38- as needed.
32+ PowerShell includes a base set of modules. Anyone can create new modules using
33+ C# or the PowerShell scripting language itself. Modules written in C# as
34+ compiled .NET assemblies are known as native modules. Modules written in
35+ PowerShell are known as script modules.
3936
40- You can write modules in C# as compiled .NET assemblies, known as native
41- modules, or in plain PowerShell, known as script modules. This topic explains
42- how to use PowerShell modules. For information about how to create PowerShell
43- modules, see [ Writing a PowerShell Module] [ 02 ] .
37+ This article explains how to use PowerShell modules. For information about how
38+ to create PowerShell modules, see [ Writing a PowerShell Module] [ 02 ] .
4439
4540>  [ !NOTE] 
4641>  Prior to PowerShell 3.0, cmdlets and providers were packaged in PowerShell
@@ -49,42 +44,13 @@ modules, see [Writing a PowerShell Module][02].
4944>  remaining in PowerShell. All other snap-ins were converted to modules.
5045>  Creation of new snap-ins is no longer supported.
5146
52- ## Install a published  module 
47+ ## Default  module locations  
5348
54- A published module is a module that is available from a registered repository,
55- such as the PowerShell Gallery. The ** PowerShellGet**  and
56- ** Microsoft.PowerShell.PSResourceGet**  modules provide cmdlets for finding,
57- installing, and publishing PowerShell modules to a registered repository.
49+ PowerShell stores modules in the following default locations:
5850
59- The ** PowerShellGet**  module is included with PowerShell 5.0 and later
60- releases. The ** Microsoft.PowerShell.PSResourceGet**  module is included with
61- PowerShell 7.4 and later releases. ** Microsoft.PowerShell.PSResourceGet**  is
62- the new preferred package manager for PowerShell and can be installed on
63- previous versions of PowerShell. Use the ` Install-Module `  or
64- ` Install-PSResource `  cmdlet to install modules from the PowerShell Gallery.
65- 
66- ``` powershell 
67-  Get-Command Install-Module, Install-PSResource 
68- ``` 
69- 
70- ``` Output 
71- CommandType  Name                Version    Source 
72- -----------  ----                -------    ------ 
73- Function     Install-Module      2.9.0      PowerShellGet 
74- Cmdlet       Install-PSResource  1.0.0      Microsoft.PowerShell.PSResourceGet 
75- ``` 
76- 
77- For more information, see [ PowerShellGet Overview] [ 01 ] .
78- 
79- ## Manually install a module  
80- 
81- If you receive a module as a folder with files in it, you need to install it on
82- your computer before you can use it in PowerShell.
83- 
84- PowerShell comes with several preinstalled modules. On Windows-based computers,
85- many Windows features include modules for managing the feature. Those modules
86- get installed when the feature is installed. Other modules may come in an
87- installer or setup program that installs the module.
51+   -  All users scope - ` $env:ProgramFiles\WindowsPowerShell\Modules ` 
52+   -  Current user scope - ` $HOME\Documents\WindowsPowerShell\Modules ` 
53+   -  Modules shipped with PowerShell - ` $PSHOME\Modules ` 
8854
8955By default, the ` Modules `  folder for the current user doesn't exist. If you
9056installed a module in the ` CurrentUser `  scope using ` Install-Module `  or
@@ -97,31 +63,19 @@ Use the following command to create a `Modules` folder for the current user:
9763$folder = New-Item -Type Directory -Path $HOME\Documents\WindowsPowerShell\Modules 
9864``` 
9965
100- Copy the entire module folder into the new created folder. In PowerShell use
101- the ` Copy-Item `  cmdlet. For example, run the following command to copy the
102- ` MyModule `  folder from ` C:\PSTest `  to the folder you just created:
103- 
104- ``` powershell 
105- Copy-Item -Path C:\PSTest\MyModule -Destination $folder 
106- ``` 
107- 
108- You can install a module in any location, but installing your modules in a
109- default module location makes them easier to manage. For more information about
110- the default module locations, see [ about_PSModulePath] [ 10 ] .
66+ These locations are automatically included in the ` $env:PSModulePath ` 
67+ environment variable. For more information about the default module locations,
68+ see [ about_PSModulePath] [ 10 ] .
11169
11270## Module autoloading  
11371
11472The first time that you run a command from an installed module, PowerShell
11573automatically imports (loads) that module. The module must be stored in the
116- locations specified in the ` $env:PSModulePath `  environment variable. Modules in
117- other locations must be imported using the ` Import-Module `  cmdlet.
74+ locations specified in the ` $env:PSModulePath `  environment variable.
11875
11976Module autoloading allows you to use commands in a module without any setup or
120- profile configuration. There's no need to manage modules after you install them
121- on your computer.
122- 
123- Each of the following examples cause the ** CimCmdlets**  module, which contains
124- ` Get-CimInstance ` , to be imported into your session.
77+ profile configuration. Each of the following examples causes the ** CimCmdlets** 
78+ module, which contains ` Get-CimInstance ` , to be imported into your session.
12579
12680-  Run the Command
12781
@@ -141,17 +95,9 @@ Each of the following examples cause the **CimCmdlets** module, which contains
14195  Get-Help Get-CimInstance 
14296``` 
14397
144- You can use the ` Get-Command `  cmdlet list the commands in all installed
145- modules, even if they're not yet in the session. When you use ` Get-Command ` 
146- with a wildcard character (` * ` ), PowerShell doesn't import any modules. You can
147- use wildcards for command discovery without loading modules that you may not
148- need in your session.
149- 
150- Also, commands that use PowerShell providers don't automatically import a
151- module. For example, if you use a command that requires the ` WSMan: `  drive,
152- such as the ` Get-PSSessionConfiguration `  cmdlet, you might need to run the
153- ` Import-Module `  cmdlet to import the ** Microsoft.WSMan.Management**  module that
154- includes the ` WSMan: `  drive.
98+ When you use ` Get-Command `  with a wildcard character (` * ` ), PowerShell doesn't
99+ import any modules. You can use wildcards for command discovery without loading
100+ modules that you might not need in your session.
155101
156102## Manually import a module  
157103
@@ -160,16 +106,21 @@ locations specified by the `$env:PSModulePath` environment variable, or when
160106the module is provided as a standalone ` .dll `  or ` .psm1 `  file, rather than a
161107packaged module.
162108
109+ Also, commands that use PowerShell providers don't automatically import a
110+ module. For example, if you use a command that requires the ` WSMan: `  drive,
111+ such as the ` Get-PSSessionConfiguration `  cmdlet, you might need to run the
112+ ` Import-Module `  cmdlet to import the ** Microsoft.WSMan.Management**  module that
113+ includes the ` WSMan: `  drive.
114+ 
163115You might also want to change how the module is imported in your session. For
164116example, the ** Prefix**  parameter of ` Import-Module `  adds a distinctive prefix
165117to the noun portion of the cmdlets imported from the module. The ** NoClobber** 
166118parameter prevents the module from adding commands that would hide or replace
167119existing commands in the session. For more information, see
168120[ Manage name conflicts] [ 03 ] .
169121
170- You can import a module that's installed in your ` $env:PSModulePath `  by
171- specifying the module name. For example, the following command imports the
172- ** BitsTransfer**  module into the current session.
122+ The following example imports the ** BitsTransfer**  module into the current
123+ session.
173124
174125``` powershell 
175126Import-Module BitsTransfer 
@@ -202,10 +153,56 @@ the `Import-Module` command to your PowerShell profile.
202153
203154For more information about profiles, see [ about_Profiles] [ 09 ] .
204155
156+ ## Install a published module  
157+ 
158+ A published module is a module that's available from a registered repository,
159+ such as the PowerShell Gallery. The ** PowerShellGet**  and
160+ ** Microsoft.PowerShell.PSResourceGet**  modules provide cmdlets for finding,
161+ installing, and publishing PowerShell modules to a registered repository.
162+ 
163+ The ** PowerShellGet**  module is included with PowerShell 5.0 and later
164+ releases. The ** Microsoft.PowerShell.PSResourceGet**  module is included with
165+ PowerShell 7.4 and later releases and is the preferred package manager for
166+ PowerShell. ** Microsoft.PowerShell.PSResourceGet**  can be installed, side by
167+ side with ** PowerShellGet** , on older versions of PowerShell. Use the
168+ ` Install-Module `  or ` Install-PSResource `  cmdlet to install modules from the
169+ PowerShell Gallery.
170+ 
171+ ``` powershell 
172+  Get-Command Install-Module, Install-PSResource 
173+ ``` 
174+ 
175+ ``` Output 
176+ CommandType  Name                Version    Source 
177+ -----------  ----                -------    ------ 
178+ Function     Install-Module      2.9.0      PowerShellGet 
179+ Cmdlet       Install-PSResource  1.0.0      Microsoft.PowerShell.PSResourceGet 
180+ ``` 
181+ 
182+ For more information, see [ PowerShellGet Overview] [ 01 ] .
183+ 
184+ ## Manually install a module  
185+ 
186+ You can manually install a module by copying the module contents from another
187+ folder. That folder can be in another location on the local machine or
188+ installed on another machine. To install a module manually, copy the entire
189+ module folder into a new location included in your ` $env:PSModulePath ` .
190+ 
191+ In PowerShell use the ` Copy-Item `  cmdlet. For example, run the following
192+ command to copy the ` MyModule `  folder from ` C:\PSTest ` :
193+ 
194+ ``` powershell 
195+ $modulePath = $HOME\Documents\PowerShell\Modules\MyModule 
196+ Copy-Item -Path C:\PSTest\MyModule\* -Destination $modulePath -Recurse 
197+ ``` 
198+ 
199+ You can install a module in any location, but installing your modules in a
200+ default module location makes them easier to manage.
201+ 
205202## Find installed modules  
206203
207- The ` Get-Module `  cmdlet gets the PowerShell modules that have been imported in 
208- your  session.
204+ The ` Get-Module `  cmdlet gets the PowerShell modules that are loaded in the 
205+ current PowerShell  session.
209206
210207``` powershell 
211208Get-Module 
@@ -312,7 +309,7 @@ have the same names as commands or items in the session.
312309current session. Name conflicts can result in commands being hidden or
313310replaced. Command replacement occurs when the imported module contains a
314311command with the same name as an existing command in the session. The newly
315- imported command replaces  takes precedence over the existing command.
312+ imported command takes precedence over the existing command.
316313
317314For example, when a session includes a function and a cmdlet with the same
318315name, PowerShell runs the function by default. When the session includes
@@ -322,9 +319,9 @@ name, by default, it runs the most recently added command.
322319For more information, including an explanation of the precedence rules and
323320instructions for running hidden commands, see [ about_Command_Precedence] [ 04 ] .
324321
325- You can run a command that has been  hidden or replaced by qualifying the
326- command name. To  qualify the command name, add the name of module than  contains
327- the version of the  command you want. For example:
322+ You can run a hidden or replaced command  by qualifying the command name. To 
323+ qualify the command name, add the name of module that  contains the version of 
324+ the command you want. For example:
328325
329326``` powershell 
330327Microsoft.PowerShell.Utility\Get-Date 
0 commit comments