24

I wanted to see colorized filenames when I typed dir in Powershell. So, I added the Set-ChildItemColor function from here to my profile file. I also added this line at the end of the profile file to override the dir alias:

Set-Alias dir Get-ChildItemColor

Now, when I open Powershell, I get this error:

Set-Alias : The AllScope option cannot be removed from the alias 'dir'.
At C:\Users\joe\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:82
char:10
+ Set-Alias <<<<  dir Get-ChildItemColor
    + CategoryInfo          : WriteError: (dir:String) [Set-Alias], SessionStateUna
   uthorizedAccessException
    + FullyQualifiedErrorId : AliasAllScopeOptionCannotBeRemoved,Microsoft.PowerShe
   ll.Commands.SetAliasCommand

What is this AllScope? How do I remove that option to get colorized dir?

1
  • Not sure why this was closed.. I had exactly this ("AllScope option cannot be removed") and the answer below solved my problem.
    – John Fouhy
    Commented Aug 5, 2013 at 4:32

2 Answers 2

38

Use the -Option parameter of Set-Alias.

Set-Alias -Name dir -Value Set-ChildItemColor -Option AllScope

See Get-Help Set-Alias and Get-Help about_Scope for details.

0

For anyone who is getting a similar issue when aliasing cd to the z command when using zoxide I was able to fix this by doing this

#Open your $Profile file on notepad
PS c:\Users\[Your user]> notepad $PROFILE

# [Paste this line to your your $PROFILE file]
# (C:\Users\[user]\Powershell.Microsoft.Powershell_ps1 by default) 
Set-Alias -Name cd -Value z -Option AllScope

# Source your prompt to enable the alias
PS C:\Users\[Your User]\> . $PROFILE 
1
  • Might not be the original issue but might help when one is using zoxide Commented Aug 24 at 20:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .