Repository navigation
Expand file tree
/
Copy pathSet-PSMDModulePath.ps1
More file actions
80 lines (65 loc) · 2.35 KB
/
Copy pathSet-PSMDModulePath.ps1
File metadata and controls
80 lines (65 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
function Set-PSMDModulePath
{
<#
.SYNOPSIS
Sets the path of the module currently being developed.
.DESCRIPTION
Sets the path of the module currently being developed.
This is used by several utility commands in order to not require any path input.
This is a wrapper around the psframework configuration system, the same action can be taken by running this command:
Set-PSFConfig -Module PSModuleDevelopment -Name "Module.Path" -Value $Path
.PARAMETER Module
The module, the path of which to register.
.PARAMETER Path
The path to set as currently developed module.
.PARAMETER Register
Register the specified path, to have it persist across sessions
.PARAMETER EnableException
Replaces user friendly yellow warnings with bloody red exceptions of doom!
Use this if you want the function to throw terminating errors you want to catch.
.EXAMPLE
Set-PSMDModulePath -Path "C:\github\dbatools"
Sets the current module path to "C:\github\dbatools"
.EXAMPLE
Set-PSMDModulePath -Path "C:\github\dbatools" -Register
Sets the current module path to "C:\github\dbatools"
Then stores the setting in registry, causing it to be persisted acros multiple sessions.
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'Module')]
[System.Management.Automation.PSModuleInfo]
$Module,
[Parameter(Mandatory = $true, ParameterSetName = 'Path')]
[string]
$Path,
[switch]
$Register,
[switch]
$EnableException
)
process
{
if ($Path)
{
$resolvedPath = Resolve-PSFPath -Path $Path -Provider FileSystem -SingleItem
if (Test-Path -Path $resolvedPath)
{
if ((Get-Item $resolvedPath).PSIsContainer)
{
Set-PSFConfig -Module PSModuleDevelopment -Name "Module.Path" -Value $resolvedPath
if ($Register) { Register-PSFConfig -Module 'PSModuleDevelopment' -Name 'Module.Path' }
return
}
}
Stop-PSFFunction -Target $Path -Message "Could not validate/resolve path: $Path" -EnableException $EnableException -Category InvalidArgument
return
}
else
{
Set-PSFConfig -Module PSModuleDevelopment -Name "Module.Path" -Value $Module.ModuleBase
if ($Register) { Register-PSFConfig -Module 'PSModuleDevelopment' -Name 'Module.Path' }
}
}
}