2020-09-16 15:57:55 +00:00
|
|
|
[CmdletBinding(SupportsShouldProcess)]param()
|
|
|
|
|
|
|
|
$local:allAliases = @()
|
|
|
|
|
|
|
|
$MyAliasScope = 0
|
|
|
|
$local:_scope = 0
|
|
|
|
$local:_done = $false
|
|
|
|
do {
|
|
|
|
try {
|
|
|
|
$local:newAliases += Get-Alias -Scope $_scope |
|
|
|
|
Where-Object {
|
2020-09-18 19:41:58 +00:00
|
|
|
($_.Definition -match "^$MyPSScriptRoot") -or ($_.Description -match '#MyAlias')
|
2020-09-16 15:57:55 +00:00
|
|
|
}
|
|
|
|
if( $newAliases ) {
|
|
|
|
$allAliases += $newAliases
|
|
|
|
$MyAliasScope = $_scope;
|
|
|
|
Write-Verbose "`$MyAliasScope is now set to $MyAliasScope"
|
|
|
|
}
|
|
|
|
} catch {
|
2020-09-18 19:41:58 +00:00
|
|
|
Write-Verbose "catch: $($_.Exception.Message)"
|
|
|
|
$_done = $_.Exception.Message -match 'The scope .* exceeds'
|
2020-09-16 15:57:55 +00:00
|
|
|
}
|
2020-09-18 19:41:58 +00:00
|
|
|
$_scope += 1
|
|
|
|
} until ( $_done )
|
2020-09-16 15:57:55 +00:00
|
|
|
|
|
|
|
$allAliases
|