|
1 | | -function Set-PSUPath { |
2 | | - <# |
| 1 | +function Set-PSUPath |
| 2 | +{ |
| 3 | +<# |
3 | 4 | .SYNOPSIS |
4 | 5 | Detects the alias that called it and sets the location to the corresponding path found in the configuration system. |
5 | 6 |
|
|
23 | 24 | Set-PSUPath detected that 'Software' was the alias that called it and then sends it to the path. |
24 | 25 | It receives the path from Get-PSUPathAlias 'software' |
25 | 26 | #> |
26 | | - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] |
27 | | - [CmdletBinding()] |
28 | | - param ( |
29 | | - $Alias = $MyInvocation.line, |
30 | | - |
31 | | - [switch] |
32 | | - $EnableException |
33 | | - ) |
34 | | - |
35 | | - Write-PSFMessage -Level InternalComment -Message "Bound parameters: $($PSBoundParameters.Keys -join ", ")" -Tag 'debug', 'start', 'param' |
36 | | - try { |
37 | | - $PSFConfigPath = Get-PSFConfigValue -FullName psutil.pathalias.$Alias -NotNull |
38 | | - } |
39 | | - |
40 | | - catch { |
41 | | - Stop-PSFFunction -Message "Unable to find a path setting for the alias" -Category InvalidOperation -Tag fail -Exception $_ |
42 | | - return |
43 | | - } |
44 | | - |
45 | | - try { |
46 | | - |
47 | | - if ($PSFConfigPath -contains '$env:') { |
48 | | - Write-PSFMessage "Environmental variable detected, resolving path" -Level internalcomment |
49 | | - Set-Location (Resolve-Path $PSFConfigPath) |
50 | | - } |
51 | | - |
52 | | - else { |
53 | | - Set-Location $PSFConfigPath |
54 | | - } |
55 | | - } |
56 | | - catch { |
57 | | - |
58 | | - $psfFuncParams = @{ |
59 | | - Message = "Unable to set location to $PSFConfigPath" |
60 | | - Category = 'InvalidOperation' |
61 | | - Tag = 'fail' |
62 | | - ErrorRecord = $_ |
63 | | - EnableException = $EnableException |
64 | | - } |
65 | | - Stop-PSFFunction @psfFuncParams |
66 | | - return |
67 | | - } |
| 27 | + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] |
| 28 | + [CmdletBinding()] |
| 29 | + param ( |
| 30 | + $Alias = $MyInvocation.line, |
| 31 | + |
| 32 | + [switch] |
| 33 | + $EnableException |
| 34 | + ) |
| 35 | + |
| 36 | + Write-PSFMessage -Level InternalComment -Message "Bound parameters: $($PSBoundParameters.Keys -join ", ")" -Tag 'debug', 'start', 'param' |
| 37 | + try |
| 38 | + { |
| 39 | + $PSFConfigPath = Get-PSFConfigValue -FullName psutil.pathalias.$Alias -NotNull |
| 40 | + } |
| 41 | + |
| 42 | + catch |
| 43 | + { |
| 44 | + Stop-PSFFunction -Message "Unable to find a path setting for the alias" -Category InvalidOperation -Tag fail -Exception $_ |
| 45 | + return |
| 46 | + } |
| 47 | + |
| 48 | + try |
| 49 | + { |
| 50 | + |
| 51 | + if ($PSFConfigPath -contains '$env:') |
| 52 | + { |
| 53 | + Write-PSFMessage "Environmental variable detected, resolving path" -Level internalcomment |
| 54 | + Set-Location (Resolve-Path $PSFConfigPath) |
| 55 | + } |
| 56 | + |
| 57 | + else |
| 58 | + { |
| 59 | + Set-Location $PSFConfigPath |
| 60 | + } |
| 61 | + } |
| 62 | + catch |
| 63 | + { |
| 64 | + |
| 65 | + $psfFuncParams = @{ |
| 66 | + Message = "Unable to set location to $PSFConfigPath" |
| 67 | + Category = 'InvalidOperation' |
| 68 | + Tag = 'fail' |
| 69 | + ErrorRecord = $_ |
| 70 | + EnableException = $EnableException |
| 71 | + } |
| 72 | + Stop-PSFFunction @psfFuncParams |
| 73 | + return |
| 74 | + } |
68 | 75 | } |
0 commit comments