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

如何配置PowerShell启动时加载本地C盘的profile.ps1脚本

解决PowerShell加载本地profile.ps1的问题

核心说明

$PROFILE是PowerShell内置的自动变量,不是环境变量,所以手动添加系统环境变量PROFILE不会生效。要让PowerShell加载本地C盘的profile文件,可按以下方法操作:


方法一:通过默认profile导入本地配置

  • 打开默认的OneDrive路径下的profile文件:
    notepad $PROFILE
    
  • 在文件末尾添加一行点源命令,指向你的本地profile路径(替换为实际路径):
    . C:\Users\Joey\LocalDocs\WindowsPowerShell\profile.ps1
    
    (注意:点号后必须加空格,用于导入并执行指定脚本)
  • 保存文件后,PowerShell启动时会先执行OneDrive的默认profile,再加载你本地的配置。

方法二:修改快捷方式启动参数(仅针对该快捷方式启动的PowerShell)

  • 找到PowerShell的快捷方式(开始菜单/任务栏),右键选择「属性」
  • 在「目标」输入框的末尾,添加以下参数(替换为你的本地profile路径):
    -NoProfile -Command ". C:\Users\Joey\LocalDocs\WindowsPowerShell\profile.ps1"
    
    • -NoProfile:阻止PowerShell加载默认的OneDrive路径profile
    • -Command:启动时执行指定的点源命令,加载本地profile
  • 点击「确定」,以后通过该快捷方式启动PowerShell就会直接加载本地配置。

方法三:通过注册表全局配置(所有PowerShell实例生效)

  • 打开注册表编辑器:
    regedit
    
  • 定位到以下路径:
    HKEY_CURRENT_USER\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell
    
  • 若不存在StartupScript项,右键新建「字符串值」,命名为StartupScript
  • 将StartupScript的值设置为你的本地profile路径,示例:
    C:\Users\Joey\LocalDocs\WindowsPowerShell\profile.ps1
    
  • (可选)若本地脚本执行被阻止,执行以下命令调整执行策略:
    Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
    
    该策略允许执行本地创建的脚本,远程下载的脚本需签名验证。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 20:52:04