1
1
---
2
- ms.date : 11/29/2017
2
+ ms.date : 09/09/2019
3
3
schema : 2.0.0
4
4
locale : en-us
5
5
keywords : powershell,cmdlet
@@ -8,7 +8,6 @@ title: about_Modules
8
8
# About Modules
9
9
10
10
## Short Description
11
-
12
11
Explains how to install, import, and use PowerShell modules.
13
12
14
13
## Long Description
@@ -32,34 +31,35 @@ are added by a module or a snap-in.
32
31
33
32
## Module Auto-Loading
34
33
35
- Beginning in PowerShell 3.0, PowerShell imports modules automatically the
36
- first time that you run any command in an installed module. You can now use
37
- the commands in a module without any set-up or profile configuration, so
38
- there's no need to manage modules after you install them on your computer.
34
+ Beginning in PowerShell 3.0, PowerShell imports modules automatically the first
35
+ time that you run any command in an installed module. You can now use the
36
+ commands in a module without any set-up or profile configuration, so there's no
37
+ need to manage modules after you install them on your computer.
39
38
40
39
The commands in a module are also easier to find. The ` Get-Command ` cmdlet now
41
40
gets all commands in all installed modules, even if they are not yet in the
42
41
session, so you can find a command and use it without importing.
43
42
44
- Any of the following commands will import a module into your session.
43
+ Each of the following examples cause the module containing ` Get-Mailbox ` to be
44
+ imported into your session.
45
45
46
- ### Run the Command
46
+ - Run the Command
47
47
48
- ``` powershell
49
- Get-Mailbox -Identity Chris
50
- ```
48
+ ``` powershell
49
+ Get-Mailbox -Identity Chris
50
+ ```
51
51
52
- ### Get the Command
52
+ - Get the Command
53
53
54
- ``` powershell
55
- Get-Command Get-Mailbox
56
- ```
54
+ ``` powershell
55
+ Get-Command Get-Mailbox
56
+ ```
57
57
58
- ### Get Help for the Command
58
+ - Get Help for the Command
59
59
60
- ``` powershell
61
- Get-Help Get-Mailbox
62
- ```
60
+ ``` powershell
61
+ Get-Help Get-Mailbox
62
+ ```
63
63
64
64
` Get-Command ` commands that include a wildcard character (* ) are considered
65
65
to be for discovery, not use, and do not import any modules.
@@ -74,9 +74,9 @@ as the `Get-PSSessionConfiguration` cmdlet, you might need to run the
74
74
` Import-Module ` cmdlet to import the ** Microsoft.WSMan.Management** module that
75
75
includes the ` WSMan: ` drive.
76
76
77
- You can still run the ` Import-Module ` command to import a module and
78
- use the ` $PSModuleAutoloadingPreference ` variable to enable, disable and
79
- configure automatic importing of modules. For more information, see
77
+ You can still run the ` Import-Module ` command to import a module and use the
78
+ ` $PSModuleAutoloadingPreference ` variable to enable, disable and configure
79
+ automatic importing of modules. For more information, see
80
80
[ about_Preference_Variables] ( about_Preference_Variables.md ) .
81
81
82
82
## How to Use a Module
@@ -99,13 +99,13 @@ Most modules are installed for you. PowerShell comes with several preinstalled
99
99
modules, sometimes called the "core" modules. On Windows-based computers, if
100
100
features that are included with the operating system have cmdlets to manage
101
101
them, those modules are preinstalled. When you install a Windows feature, by
102
- using, for example, the Add Roles and Features Wizard in Server Manager, or
103
- the Turn Windows features on or off dialog box in Control Panel, any
104
- PowerShell modules that are part of the feature are installed. Many other
105
- modules come in an installer or Setup program that installs the module.
102
+ using, for example, the Add Roles and Features Wizard in Server Manager, or the
103
+ Turn Windows features on or off dialog box in Control Panel, any PowerShell
104
+ modules that are part of the feature are installed. Many other modules come in
105
+ an installer or Setup program that installs the module.
106
106
107
- Create a Modules directory for the current user if one does not exist. To
108
- create a Modules directory, type :
107
+ Use the following command to create a ** Modules** directory for the current
108
+ user :
109
109
110
110
``` powershell
111
111
New-Item -Type Directory -Path $HOME\Documents\WindowsPowerShell\Modules
@@ -122,21 +122,22 @@ Copy-Item -Path C:\ps-test\MyModule -Destination `
122
122
```
123
123
124
124
You can install a module in any location, but installing your modules in a
125
- default module location makes them easier to manage. For more information
126
- about the default module locations, see the "Module and DSC Resource
127
- Locations, and PSModulePath" section.
125
+ default module location makes them easier to manage. For more information about
126
+ the default module locations, see the
127
+ [ Module and DSC Resource Locations, and PSModulePath] ( #module-and-dsc-resource-locations-and-psmodulepath )
128
+ section.
128
129
129
130
## How to Find Installed Modules
130
131
131
- To find modules that are installed in a default module location,
132
- but not yet imported into your session, type:
132
+ To find modules that are installed in a default module location, but not yet
133
+ imported into your session, type:
133
134
134
135
``` powershell
135
136
Get-Module -ListAvailable
136
137
```
137
138
138
- To find the modules that have already been imported into your session,
139
- at the PowerShell prompt, type:
139
+ To find the modules that have already been imported into your session, at the
140
+ PowerShell prompt, type:
140
141
141
142
``` powershell
142
143
Get-Module
@@ -169,8 +170,8 @@ For more information about the `Get-Command` cmdlet, see
169
170
## How to Get Help for the Commands in a Module
170
171
171
172
If the module contains Help files for the commands that it exports, the
172
- ` Get-Help ` cmdlet will display the Help topics. Use the same ` Get-Help `
173
- command format that you would use to get help for any command in PowerShell.
173
+ ` Get-Help ` cmdlet will display the Help topics. Use the same ` Get-Help ` command
174
+ format that you would use to get help for any command in PowerShell.
174
175
175
176
Beginning in PowerShell 3.0, you can download Help files for a module and
176
177
download updates to the Help files so they are never obsolete.
@@ -226,21 +227,21 @@ into the current session.
226
227
Import-Module BitsTransfer
227
228
```
228
229
229
- To import a module that is not in a default module location, use
230
- the fully qualified path to the module folder in the command.
230
+ To import a module that is not in a default module location, use the fully
231
+ qualified path to the module folder in the command.
231
232
232
- For example, to add the TestCmdlets module in the C:\ps-test directory
233
- to your session, type:
233
+ For example, to add the TestCmdlets module in the ` C:\ps-test ` directory to your
234
+ session, type:
234
235
235
236
``` powershell
236
237
Import-Module C:\ps-test\TestCmdlets
237
238
```
238
239
239
- To import a module file that is not contained in a module folder, use
240
- the fully qualified path to the module file in the command.
240
+ To import a module file that is not contained in a module folder, use the fully
241
+ qualified path to the module file in the command.
241
242
242
- For example, to add the TestCmdlets.dll module in the C:\ps-test directory
243
- to your session, type:
243
+ For example, to add the TestCmdlets.dll module in the ` C:\ps-test ` directory to
244
+ your session, type:
244
245
245
246
``` powershell
246
247
Import-Module C:\ps-test\TestCmdlets.dll
@@ -251,12 +252,9 @@ For more information about adding modules to your session, see
251
252
252
253
## How to Import a Module into Every Session
253
254
254
- The ` Import-Module ` command imports modules into your current Windows
255
- PowerShell session. This command affects only the current session.
256
-
257
- To import a module into every PowerShell session that you
258
- start, add the ` Import-Module ` command to your PowerShell
259
- profile.
255
+ The ` Import-Module ` command imports modules into your current PowerShell
256
+ session. To import a module into every PowerShell session that you start, add
257
+ the ` Import-Module ` command to your PowerShell profile.
260
258
261
259
For more information about profiles, see [ about_Profiles] ( about_Profiles.md ) .
262
260
@@ -280,32 +278,33 @@ Remove-Module BitsTransfer
280
278
```
281
279
282
280
Removing a module reverses the operation of importing a module. Removing
283
- a module does not uninstall the module. For more information about the
284
- ` Remove-Module ` cmdlet, see [ Remove-Module] ( ../Remove-Module.md ) .
281
+ a module does not uninstall the module. For more information, see
282
+ [ Remove-Module] ( ../Remove-Module.md ) .
285
283
286
284
## Module and DSC Resource Locations, and PSModulePath
287
285
288
286
The following are default locations for PowerShell modules. Starting in
289
287
PowerShell 4.0, with the introduction of DSC, a new default module and DSC
290
288
resource folder was introduced. For more information about DSC, see
291
- about_DesiredStateConfiguration.
289
+ [ about_DesiredStateConfiguration] ( /powershell/module/Microsoft.PowerShell.Core/About/about_DesiredStateConfiguration ) .
292
290
293
- - System: ` $pshome \Modules ` or
291
+ - System: ` $PSHOME \Modules ` or
294
292
(` $env:windir\System32\WindowsPowerShell\v1.0\Modules ` )
295
293
System modules are those that ship with Windows and PowerShell.
296
294
297
295
Starting in PowerShell 4.0, when PowerShell Desired State Configuration
298
296
(DSC) was introduced, DSC resources that are included with PowerShell are
299
297
also stored in ` $PSHOME\Modules ` , in the
300
- ` $pshome \Modules\PSDesiredStateConfiguration\DSCResources ` folder.
298
+ ` $PSHOME \Modules\PSDesiredStateConfiguration\DSCResources ` folder.
301
299
302
- - Current user: ` $home \Documents\WindowsPowerShell\Modules `
300
+ - Current user: ` $HOME \Documents\WindowsPowerShell\Modules `
303
301
(` $env:UserProfile\Documents\WindowsPowerShell\Modules ` )
304
302
305
303
or
306
304
307
- ` $home \My Documents\WindowsPowerShell\Modules `
305
+ ` $HOME \My Documents\WindowsPowerShell\Modules `
308
306
(` $env:UserProfile\My Documents\WindowsPowerShell\Modules ` )
307
+
309
308
This is the location for user-added modules prior to PowerShell 4.0.
310
309
311
310
In PowerShell 4.0 and later releases of PowerShell, user-added modules and DSC
@@ -352,16 +351,16 @@ $Env:PSModulePath + ";C:\ps-test\Modules"
352
351
When you add a path to ** PSModulePath** , ` Get-Module ` and ` Import-Module `
353
352
commands include modules in that path.
354
353
355
- The value that you set affects only the current session. To make the
356
- change persistent, add the command to your PowerShell profile
357
- or use System in Control Panel to change the value of the ** PSModulePath**
358
- environment variable in the registry.
354
+ The value that you set affects only the current session. To make the change
355
+ persistent, add the command to your PowerShell profile or use System in Control
356
+ Panel to change the value of the ** PSModulePath** environment variable in the
357
+ registry.
359
358
360
359
Also, to make the change persistent, you can also use the
361
360
** SetEnvironmentVariable** method of the ** System.Environment** class to add a
362
361
Path to the ** PSModulePath** environment variable.
363
362
364
- For more information about the PSModulePath variable, see
363
+ For more information about the ** PSModulePath** variable, see
365
364
[ about_Environment_Variables] ( about_Environment_Variables.md ) .
366
365
367
366
## Modules and Name Conflicts
@@ -406,10 +405,10 @@ parameters of `Import-Module` to select only the commands that you want to
406
405
import, and you can exclude commands that cause name conflicts in your
407
406
session.
408
407
409
- Module authors can prevent name conflicts by using the DefaultCommandPrefix
408
+ Module authors can prevent name conflicts by using the ** DefaultCommandPrefix**
410
409
property of the module manifest to add a default prefix to all command names.
411
- The value of the Prefix parameter takes precedence over the value of
412
- DefaultCommandPrefix.
410
+ The value of the ** Prefix** parameter takes precedence over the value of
411
+ ** DefaultCommandPrefix** .
413
412
414
413
Even if a command is hidden, you can run it by qualifying the command name
415
414
with the name of the module or snap-in in which it originated.
@@ -446,7 +445,7 @@ Get-Command <cmdlet-name> | Format-List -Property verb,noun,pssnapin,module
446
445
For example, to find the source of the ` Get-Date ` cmdlet, type:
447
446
448
447
``` powershell
449
- Get-Command Get-Date | Format-List -Property verb,noun,pssnapin, module
448
+ Get-Command Get-Date | Format-List -Property verb,noun,module
450
449
```
451
450
452
451
For more information about PowerShell snap-ins, see
@@ -459,9 +458,9 @@ rules. If the module that you import exports cmdlets or functions that have
459
458
unapproved verbs in their names, the ` Import-Module ` cmdlet displays the
460
459
following warning message.
461
460
462
- WARNING: Some imported command names include unapproved verbs which might make
463
- them less discoverable. Use the Verbose parameter for more detail or type
464
- ` Get-Verb ` to see the list of approved verbs.
461
+ > WARNING: Some imported command names include unapproved verbs which might
462
+ > make them less discoverable. Use the Verbose parameter for more detail or
463
+ > type Get-Verb to see the list of approved verbs.
465
464
466
465
This message is only a warning. The complete module is still imported,
467
466
including the non-conforming commands. Although the message is displayed to
@@ -472,18 +471,19 @@ the `Import-Module` cmdlet.
472
471
473
472
## Built-in Modules and Snap-ins
474
473
475
- In PowerShell 2.0 and in older-style host programs in PowerShell 3.0 and
476
- later, the core commands that are installed with PowerShell are packaged in
477
- snap-ins that are added automatically to every PowerShell session.
474
+ In PowerShell 2.0 and in older-style host programs in PowerShell 3.0 and later,
475
+ the core commands that are installed with PowerShell are packaged in snap-ins
476
+ that are added automatically to every PowerShell session.
478
477
479
478
Beginning in PowerShell 3.0, for host programs that implement the
480
479
` InitialSessionState.CreateDefault2 ` initial session state API the
481
- Microsoft.PowerShell.Core snap-in is added to every session by default.
482
- Modules are loaded automatically on first-use.
480
+ Microsoft.PowerShell.Core snap-in is added to every session by default. Modules
481
+ are loaded automatically on first-use.
483
482
484
- NOTE: Remote sessions, including sessions that are started by using the
485
- ` New-PSSession ` cmdlet, are older-style sessions in which the built-in
486
- commands are packaged in snap-ins.
483
+ > [ !NOTE]
484
+ > Remote sessions, including sessions that are started by using the
485
+ > ` New-PSSession ` cmdlet, are older-style sessions in which the built-in
486
+ > commands are packaged in snap-ins.
487
487
488
488
The following modules (or snap-ins) are installed with PowerShell.
489
489
- Microsoft.PowerShell.Core
0 commit comments