internal/functions/Import-PSUAlias.ps1

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
function Import-PSUAlias
{
    <#
        .SYNOPSIS
            Internal command to set aliases in a user-controlled fashion.
         
        .DESCRIPTION
            Internal command to set aliases in a user-controlled fashion.
            - Can be blocked by setting a config "PSUtil.Import.Aliases.$Name" to $false.
            - Will not overwrite existing aliases
         
        .PARAMETER Name
            Name of the alias to set.
         
        .PARAMETER Command
            Name of the command to alias.
         
        .EXAMPLE
            PS C:\> Import-PSUAlias -Name grep -Command Select-String
     
            Sets the alias grep for the command Select-String
    #>

    
    [CmdletBinding()]
    Param (
        $Name,
        
        $Command
    )
    
    if ((-not (Test-Path alias:$name)) -and (Get-PSFConfigValue -FullName PSUtil.Import.Aliases.$name -Fallback $true))
    {
        New-Alias -Name $Name -Value $Command -Option AllScope -Force -Scope Global
    }
}