如何分析Powershell的启动时间?

Yoh*_*hei 6 powershell

启动我的 powershell 需要大约 3 秒,所以我想减少它。如何知道哪个进程损害了powershell的启动性能?我想使用像vim profiling这样的工具。

And*_*ond 1

Set-PSDebug 方法:要快速查看您的配置文件是否很慢,您可以添加

Set-PSDebug -Trace 1
Run Code Online (Sandbox Code Playgroud)

到您的个人资料顶部。然后,您将能够实时观看正在执行的各行。添加Set-PSDebug -Trace 0到您的个人资料底部以将其关闭。

测量多个 $PROFILE 文件:要测量当前 $PROFILE 自动包含的不同配置文件:

$PROFILE | gm -Type NoteProperty | % {($path=$PROFILE.($_.Name)); Measure-Command{&{. $path}}}
Run Code Online (Sandbox Code Playgroud)

配置文件中的 Measure-Command:您还可以Measure-Command通过编辑配置文件来将单个命令或整个配置文件包含在内。例如,要报告您的配置文件的执行时间:

$executionTime = Measure-Command `
{
    # Your profile commands here
}

# $PSCommandPath is an automatic variable containing the path and file name of
# the script being run.
Write-Host "$PSCommandPath execution time: $executionTime"
Run Code Online (Sandbox Code Playgroud)