Skip to content

Commit 8bf8105

Browse files
Merge pull request #39 from PowershellFrameworkCollective/aliasfix
Alias & encoding update
2 parents 00bad63 + 16019a5 commit 8bf8105

40 files changed

+202
-196
lines changed

PSUtil/PSUtil.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@{
1+
@{
22
# Script module or binary module file associated with this manifest
33
ModuleToProcess = 'PSUtil.psm1'
44

PSUtil/PSUtil.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$script:ModuleRoot = $PSScriptRoot
1+
$script:ModuleRoot = $PSScriptRoot
22
$script:ModuleVersion = (Import-PowerShellDataFile -Path "$($script:ModuleRoot)\PSUtil.psd1").ModuleVersion
33

44
# Detect whether at some level dotsourcing was enforced

PSUtil/bin/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# bin folder
1+
# bin folder
22

33
The bin folder exists to store binary data. And scripts related to the type system.
44

PSUtil/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- upd: Alias `ex` now points at `Export-PSFClixml`
1010
- upd: Alias `ix` now points at `Import-PSFClixml`
1111
- upd: Alias `spo` now points at `Select-PSFObject`
12+
- upd: Moved the list of default properties to expand using Expand-PSUObject to configuration
1213

1314
## Version 1.1.5.17 (2018-06-19)
1415
- new: Command Select-PSUObject - Select-Object in awesome.

PSUtil/en-us/about_PSUtil.help.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
TOPIC
1+
TOPIC
22
about_PSUtil
33

44
SHORT DESCRIPTION

PSUtil/functions/objects/Expand-PSUObject.ps1

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434
3535
.PARAMETER InputObject
3636
The objects whose properties are to be expanded.
37-
38-
.PARAMETER RestoreDefaults
39-
Restores $DefaultExpandedProperties to the default list of property-names.
4037
4138
.EXAMPLE
4239
PS C:\> dir | exp
@@ -54,7 +51,6 @@
5451
5552
Expands all properties from all objects returned by dir that match the string "name" ("PSChildName", "FullName", "Name", "BaseName" for directories)
5653
#>
57-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidGlobalVars", "")]
5854
[CmdletBinding(DefaultParameterSetName = "Equals")]
5955
Param (
6056
[Parameter(Position = 0, ParameterSetName = "Equals")]
@@ -73,10 +69,7 @@
7369

7470
[Parameter(ValueFromPipeline = $true)]
7571
[object]
76-
$InputObject,
77-
78-
[switch]
79-
$RestoreDefaults
72+
$InputObject
8073
)
8174

8275
Begin
@@ -95,12 +88,10 @@
9588
$n9ZPiBh8CI = $Name
9689
$____found = $true
9790
}
98-
99-
# Restore to default if necessary
100-
if ($RestoreDefaults) { $global:DefaultExpandedProperties = @("Definition", "Guid", "DisinguishedName", "FullName", "Name", "Length") }
91+
$DefaultExpandedProperties = Get-PSFConfigValue -FullName 'PSutil.Expand.DefaultProperties'
10192
}
10293

103-
Process
94+
process
10495
{
10596
:main foreach ($Object in $InputObject)
10697
{
@@ -173,5 +164,4 @@
173164
Write-PSFMessage -Level Debug -Message "Expanding Objects" -Tag end
174165
}
175166
}
176-
if (-not $global:DefaultExpandedProperties) { $global:DefaultExpandedProperties = @("Definition", "Guid", "DisinguishedName", "FullName", "Name", "Length") }
177167
Import-PSUAlias -Name "exp" -Command "Expand-PSUObject"

PSUtil/functions/objects/Register-PSUObjectConversion.ps1

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@
3737
$ScriptBlock
3838
)
3939

40-
begin
41-
{
42-
Write-PSFMessage -Level InternalComment -Message "Bound parameters: $($PSBoundParameters.Keys -join ", ")" -Tag 'debug', 'start', 'param'
43-
}
4440
process
4541
{
4642
$conversion = New-Object PSUtil.Object.ObjectConversionMapping -Property @{
@@ -50,10 +46,5 @@
5046
}
5147

5248
[PSUtil.Object.ObjectHost]::Conversions["$($From):$($To)".ToLower()] = $conversion
53-
54-
}
55-
end
56-
{
57-
5849
}
5950
}
Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
function Get-PSUPathAlias {
2-
<#
1+
function Get-PSUPathAlias
2+
{
3+
<#
34
.SYNOPSIS
45
Gets the PSUPathAlias configuration values.
56
@@ -13,20 +14,22 @@
1314
1415
.EXAMPLE
1516
PS C:\> Get-PSUPathAlias
17+
1618
Returns all aliases
1719
#>
18-
[CmdletBinding()]
19-
param (
20-
[string]
21-
$Alias = '*'
22-
)
23-
24-
$aliases = Get-PSFConfig -FullName psutil.pathalias.$Alias
25-
26-
foreach ($ali in $aliases) {
27-
[pscustomobject]@{
28-
Alias = ($ali.fullname -replace '^psutil.pathalias.')
29-
Path = $ali.value
30-
}
31-
}
20+
[CmdletBinding()]
21+
param (
22+
[string]
23+
$Alias = '*'
24+
)
25+
26+
$aliases = Get-PSFConfig -FullName psutil.pathalias.$Alias
27+
28+
foreach ($alias in $aliases)
29+
{
30+
[pscustomobject]@{
31+
Alias = ($alias.fullname -replace '^psutil.pathalias.')
32+
Path = $alias.value
33+
}
34+
}
3235
}
Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
1-
function Remove-PSUPathAlias {
2-
<#
1+
function Remove-PSUPathAlias
2+
{
3+
<#
34
.SYNOPSIS
45
Removes a path alias fromm the configuration system.
6+
57
.DESCRIPTION
68
Removes a path alias from the configuration system using Unregister-PSFConfig.
79
Note: This command has no effect on configuration setings currently in memory.
10+
811
.PARAMETER Alias
912
The name of the Alias that you want to remove from the configuration system.
13+
1014
.EXAMPLE
1115
PS C:\> Remove-PSUPathAlias -Alias work
16+
1217
Removes the path alias named work from the configuration system.
1318
#>
14-
[CmdletBinding()]
15-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
16-
param (
17-
[Parameter(ValuefromPipelineByPropertyName = $true)]
18-
$Alias
19-
)
20-
21-
process {
22-
Get-PSFConfig -FullName psutil.pathalias.$Alias | Unregister-PSFConfig
23-
}
19+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
20+
[CmdletBinding()]
21+
param (
22+
[Parameter(ValuefromPipelineByPropertyName = $true)]
23+
$Alias
24+
)
25+
26+
process
27+
{
28+
Get-PSFConfig -FullName psutil.pathalias.$Alias | Unregister-PSFConfig
29+
Remove-PSFAlias -Name $Alias
30+
}
2431
}
Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
function Set-PSUPath {
2-
<#
1+
function Set-PSUPath
2+
{
3+
<#
34
.SYNOPSIS
45
Detects the alias that called it and sets the location to the corresponding path found in the configuration system.
56
@@ -23,46 +24,52 @@
2324
Set-PSUPath detected that 'Software' was the alias that called it and then sends it to the path.
2425
It receives the path from Get-PSUPathAlias 'software'
2526
#>
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+
}
6875
}

0 commit comments

Comments
 (0)