-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
James Brundage
committed
May 27, 2024
1 parent
284bc0d
commit 8b58c9e
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
[ValidatePattern('Mount[-\.]Module')] | ||
param() | ||
function Mount-Module | ||
{ | ||
<# | ||
.SYNOPSIS | ||
Mounts a module. | ||
.DESCRIPTION | ||
Mounts a module as a PSDrive. | ||
This can shorten paths considerably, and make it easier to work with a module's contents. | ||
.EXAMPLE | ||
Get-Module PipeScript | Mount-Module | ||
.EXAMPLE | ||
Mount-Module -Name Microsoft.PowerShell.Management | ||
#> | ||
[Alias('Mount.Module')] | ||
param( | ||
# The name of the module | ||
[vfp()] | ||
[Alias('ModuleName')] | ||
[string] | ||
$Name, | ||
|
||
# The root of the module. | ||
[vfp()] | ||
[string] | ||
$Root, | ||
|
||
# The description | ||
[vfp()] | ||
[string] | ||
$Description | ||
) | ||
|
||
process { | ||
# Get the piped in object | ||
$pipedIn = $_ | ||
# If we have no name, return | ||
return if -not $name | ||
|
||
if ($pipedIn -is [Management.Automation.PSModuleInfo]) { | ||
if (-not $root) { | ||
$root = $pipedIn | Split-Path | ||
} | ||
} | ||
if (-not $root) { | ||
# Get the root of the module | ||
$root = Get-Module $Name | Select-Object -First 1 | Split-Path | ||
# Return if we could not get the root (no module is loaded) | ||
return if (-not $? -or -not $root) | ||
} | ||
# If we have no description, use the name | ||
if (-not $Description) { $Description = $Name } | ||
# Mount the module | ||
New-PSDrive -Name $name -PSProvider FileSystem -Root $root -Description $description -ErrorAction Ignore -Scope Global | ||
} | ||
} |