You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell别名存储位置及自定义永久别名添加方法

Nice question! Let's break this down clearly so you can find those preset aliases and add your own permanent ones easily.

System Preset Alias Storage Locations

PowerShell's preset aliases fall into two main categories, each with different storage behavior:

  • Built-in Read-Only Aliases
    These are core aliases like dir (mapped to Get-ChildItem), ls, and cd that are baked directly into the PowerShell engine. They aren't stored in any physical file—instead, they're loaded automatically when PowerShell starts up. You can spot them by running:

    Get-Alias | Where-Object { $_.Options -match "ReadOnly" }
    

    These aliases can't be modified or deleted since they're part of PowerShell's default system configuration.

  • Profile-Based Preset Aliases
    Some preset aliases might be defined in system-wide or user-specific PowerShell profile files. These files run automatically when PowerShell starts, and they can include customizations set by your system admin or previous configurations. Common profile paths are:

    • System-wide (all users): $PSHome\Profile.ps1 and $PSHome\Microsoft.PowerShell_profile.ps1
    • User-specific (current user): $HOME\Documents\PowerShell\Profile.ps1 and $HOME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
      Note: For older PowerShell versions (5.1 and below), the user profile path is $HOME\Documents\WindowsPowerShell instead.
Adding Permanent Custom Aliases

Temporary aliases (created with Set-Alias in a single session) disappear when you close PowerShell. To make them stick across sessions, you need to add them to your PowerShell profile. Here's how:

  1. Check if your profile exists
    Run this command to verify if you have a user-specific profile already:

    Test-Path $PROFILE
    

    If it returns False, create the profile file with:

    New-Item -Path $PROFILE -ItemType File -Force
    
  2. Add your alias definition
    Open the profile file in your preferred editor (Notepad works for quick edits):

    notepad $PROFILE
    

    Use either Set-Alias (overwrites existing aliases if they exist) or New-Alias (throws an error if the alias already exists) to define your alias. Examples:

    • Map np to open Notepad:
      Set-Alias -Name np -Value notepad.exe
      
    • Map ll to run a detailed directory listing:
      Set-Alias -Name ll -Value Get-ChildItem -ArgumentList "-Force", "-Recurse"
      
  3. Apply the changes
    Save the profile file, then either:

    • Restart PowerShell, or
    • Run this command to load the updated profile in your current session:
      . $PROFILE
      
  4. Verify your alias
    Run Get-Alias <your-alias-name> (e.g., Get-Alias np) to confirm it's now available and persistent across sessions.

Quick note: If you want to add aliases for all users on the system, edit the system-wide profile files instead—but you'll need administrator privileges to do that.

内容的提问来源于stack exchange,提问作者lewis4u

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:19:14