PowerShell_Scripts/Get-MyAliases.ps1

26 rader
599 B
PowerShell

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