-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsampleProfile.ps1
More file actions
38 lines (34 loc) · 1.36 KB
/
sampleProfile.ps1
File metadata and controls
38 lines (34 loc) · 1.36 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
$aliasesPath = Join-Path -Path ([System.IO.Path]::GetDirectoryName($PROFILE)) -ChildPath "alias.txt"
function Export-AliasWithEXEInPATH
{
$aliasDict = @{}
$existingAlias = Get-Alias | ForEach-Object {$_.Name}
foreach($aliasName in $existingAlias)
{
$aliasDict.Add($aliasName,"")
}
$pathDirectories = $env:PATH.Split(';') | Where-Object {($_ -ne "") -and (Test-Path $_ )}
foreach($pathDir in $pathDirectories)
{
$result = Get-ChildItem (Join-Path $pathDir "*") -Include *.exe |
ForEach-Object {
Write-Host "Checking" $_.BaseName "for aliasing"
If(-Not $aliasDict.ContainsKey($_.BaseName))
{
$alias = $_.BaseName.ToString()
$for = $_.Name
Set-Alias -Name $alias -Value $for -Verbose -Scope "Global"
}
}
}
Export-Alias $aliasesPath
}
if(-Not (Test-Path $aliasesPath))
{
Write-Error "Cannot find alias.txt execute function Export-AliasWithEXEInPATH"
}
else
{
Import-Alias $aliasesPath -Force
}
Import-Module "PowerTab" -ArgumentList "C:\Users\bpatr\Documents\WindowsPowerShell\PowerTabConfig.xml"