PowerTip: Find PowerShell Canonical Aliases

PowerTip: Find PowerShell Canonical Aliases

  • Comments 2
  • Likes

Summary: Find Windows PowerShell aliases that are read-only and available in all scopes.

Hey, Scripting Guy! Question How can I produce a list of Windows PowerShell aliases that are read-only and are available in
           all Windows PowerShell scopes?

Hey, Scripting Guy! Answer Use the Get-Alias cmdlet to produce a list of aliases, filter on aliases that have an option of read-only,
           and select the name, definition, and options:

Get-Alias | Where options -match 'readonly' | select name, definition, options

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • I think that the right answer is as follows in case the alias is not in all scope but in readonly state.
    if the scope of all readonly aliases is "AllScope", your answer is right albeit too many ToString method is used.

    $allScopeAndReadOnly = [System.Management.Automation.ScopedItemOptions]::AllScope -bor [System.Management.Automation.ScopedItemOptions]::ReadOnly

    Get-Alias | where { ($_.Options -band $allScopeAndReadOnly) -eq $allScopeAndReadOnly } | select name, definition, options

  • thanks for sharing.