Skip to content

Commit

Permalink
feat: Mount-Module ( Fixes #1128 )
Browse files Browse the repository at this point in the history
  • Loading branch information
James Brundage committed May 27, 2024
1 parent 284bc0d commit 8b58c9e
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions Commands/Module/Mount-Module.ps.ps1
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
}
}

0 comments on commit 8b58c9e

Please sign in to comment.