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

如何让PowerShell (pwsh) 启动时始终打印配置文件加载耗时?

让PowerShell 7.3.9每次启动都显示配置文件加载耗时

PowerShell默认仅在配置文件加载耗时超过阈值(通常为500ms)时才会自动输出加载耗时提示。要实现每次启动都强制显示,你可以修改个人配置文件C:\Users\shynur\Documents\PowerShell\Profile.ps1,添加手动计算并打印耗时的代码,具体操作如下:

  • 打开该配置文件,将原有内容替换为以下代码(若需要保留sleep 13则保留对应行):
# 记录配置文件加载起始时间
$profileStart = Get-Date

# 保留原有延迟命令(不需要可删除此行)
sleep 13

# 计算并输出加载耗时
$profileEnd = Get-Date
$loadDurationMs = ($profileEnd - $profileStart).TotalMilliseconds
Write-Host "Loading personal and system profiles took $([math]::Round($loadDurationMs))ms." -ForegroundColor Gray
  • 保存配置文件后,重新启动PowerShell 7.3.9,每次启动都会显示配置文件的加载耗时。

补充说明

这段代码通过手动记录配置文件执行的起止时间,计算总耗时后模拟默认提示的格式输出,不受PowerShell内置的阈值限制。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 22:22:33