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