Launching my powershell takes about 3 sec, so I want to reduce it. How do I know which process harms the startup performance of powershell? I want to use a tool like vim profiling.
Asked
Active
Viewed 782 times
6
-
2It is probably your profile. try running a `Measure-Command` on your entire profile. – Drew Mar 28 '19 at 00:28
-
1@Drew thanks! I wrote `$profile.psobject.properties | where { $_ -is [psnoteproperty] } | foreach { echo $_.value; Measure-Command { . $_ .value }}` – tamuhey Mar 28 '19 at 01:57
-
@Yohei there is a useless space in your script. Maybe `$_ .value` should be `$_.value`? – roachsinai Feb 11 '22 at 08:36
1 Answers
1
Set-PSDebug approach: To quickly see if your profile is slow, you can add
Set-PSDebug -Trace 1
to the top of your profile. You'll then be able to watch the individual lines being executed in real-time. Add Set-PSDebug -Trace 0
to the bottom of your profile to turn it off.
Measuring your multiple $PROFILE files: To measure the different profile files automatically contained in your current $PROFILE:
$PROFILE | gm -Type NoteProperty | % {($path=$PROFILE.($_.Name)); Measure-Command{&{. $path}}}
Measure-Command within your profile: You can also wrap individual commands or your entire profile in Measure-Command
by editing your profile file. For example, to report your profile's execution time:
$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"

Andrew D. Bond
- 902
- 1
- 11
- 11