GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing learn.microsoft.com — about_Modules - PowerShell Note Access to this page requires authorization. You can try signing in or changing directories. Access to this page requires authorization. You can try changing directories. about_ModulesShort descriptionExplains how to install, import, and use PowerShell modules. Long descriptionPowerShell is both a command shell and a scripting language. Commands in PowerShell are implemented as scripts, functions, or cmdlets. The language includes keywords, which provide the structure and logic of processing, and other resources, such as variables, providers, aliases. A module is a self-contained, reusable unit that can include cmdlets,
providers, functions, variables, and other resources. By default, PowerShell
automatically loads an installed module the first time you use a command from
the module. You can configure automatic module loading behavior using the
variable You can also manually load or unload modules during a PowerShell session. To
load or reload a module, use PowerShell includes a base set of modules. Anyone can create new modules using C# or the PowerShell scripting language itself. Modules written in C# as compiled .NET assemblies are known as native modules. Modules written in PowerShell are known as script modules. This article explains how to use PowerShell modules. For information about how to create PowerShell modules, see Writing a PowerShell Module. Note Prior to PowerShell 3.0, cmdlets and providers were packaged in PowerShell snap-ins. Beginning in PowerShell 3.0, the Microsoft.PowerShell.Core snap-in is added to every session by default. This is the only snap-in remaining in PowerShell. All other snap-ins were converted to modules. Creation of new snap-ins is no longer supported. Default module locationsPowerShell stores modules in the following default locations:
By default, the Use the following command to create a
These locations are automatically included in the Module autoloadingThe first time that you run a command from an installed module, PowerShell
automatically imports (loads) that module. The module must be stored in the
locations specified in the Module autoloading allows you to use commands in a module without any setup or
profile configuration. Each of the following examples causes the CimCmdlets
module, which contains
When you use Manually import a moduleManually importing a module is required when a module isn't installed in the
locations specified by the Also, commands that use PowerShell providers don't automatically import a
module. For example, if you use a command that requires the You might also want to change how the module is imported in your session. For
example, the Prefix parameter of The following example imports the BitsTransfer module into the current session.
To import a module that isn't in your
To import a module file that isn't contained in a module folder, use the fully
qualified path to the module file in the command. For example, to add the
TestCmdlets.dll module in the
For more information about adding modules to your session, see Import-Module. Import a module at the start of every sessionThe For more information about profiles, see about_Profiles. Install a published moduleA published module is a module that's available from a registered repository, such as the PowerShell Gallery. The PowerShellGet and Microsoft.PowerShell.PSResourceGet modules provide cmdlets for finding, installing, and publishing PowerShell modules to a registered repository. The PowerShellGet module is included with PowerShell 5.0 and later
releases. The Microsoft.PowerShell.PSResourceGet module is included with
PowerShell 7.4 and later releases and is the preferred package manager for
PowerShell. Microsoft.PowerShell.PSResourceGet can be installed, side by
side with PowerShellGet, on older versions of PowerShell. Use the
For more information, see PowerShellGet Overview. Manually install a moduleYou can manually install a module by copying the module contents from another
folder. That folder can be in another location on the local machine or
installed on another machine. To install a module manually, copy the entire
module folder into a new location included in your In PowerShell use the
You can install a module in any location, but installing your modules in a default module location makes them easier to manage. Find installed modulesThe
The modules listed can include modules that were imported from any location,
not just from Use the following command to list modules that are installed in the
This command gets all modules that are installed in For more information, see Get-Module. List the commands in a moduleUse the To find all commands in a module, type:
For example, to find the commands in the BitsTransfer module, type:
For more information about the Remove a moduleWhen you remove a module, the commands that the module added are deleted from the session. For example, the following command removes the BitsTransfer module from the current session.
Removing a module reverses the operation of importing a module. Removing a module doesn't uninstall the module. For more information, see Remove-Module. Commands can be added to your session from modules and snap-ins. Modules can add all types of commands, including cmdlets, providers, and functions, and items, such as variables, aliases, and PowerShell drives. Snap-ins can add only cmdlets and providers. Before removing a module from your session, use the following commands to determine which module you want to remove. For example, use the following command to find the source of the
The following output shows that the
There are two sources for
For more information about the Manage name conflictsName conflicts occur when more than one command in the session has the same name. Importing a module causes a name conflict when commands in the module have the same names as commands or items in the session.
For example, when a session includes a function and a cmdlet with the same name, PowerShell runs the function by default. When the session includes commands of the same type with the same name, such as two cmdlets with the same name, by default, it runs the most recently added command. For more information, including an explanation of the precedence rules and instructions for running hidden commands, see about_Command_Precedence. You can run a hidden or replaced command by qualifying the command name. To qualify the command name, add the name of module that contains the version of the command you want. For example:
Running To detect name conflicts, use the All parameter of the To prevent name conflicts, use the NoClobber or Prefix parameters of
the You can also use the Alias, Cmdlet, Function, and Variable
parameters of Module authors can prevent name conflicts by using the DefaultCommandPrefix property of the module manifest to add a default prefix to all command names. The value of the Prefix parameter takes precedence over the value of DefaultCommandPrefix. See also
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
FeedbackWas this page helpful? NoAdditional resources
|
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |