Anything I do in PowerShell seems to take forever.
P> Measure-Command -Expression {Write-Output "hi"}
Days : 0
Hours : 0
Minutes : 0
Seconds : 12
Milliseconds : 513
Ticks : 125130193
TotalDays : 0.000144826612268519
TotalHours : 0.00347583869444444
TotalMinutes : 0.208550321666667
TotalSeconds : 12.5130193
TotalMilliseconds : 12513.0193
I checked my $profile, and it`s empty. But it sure takes a long time for PowerShell to tell me where my profile is:
PS F:\> Measure-Command -Expression {$profile}
Days : 0
Hours : 0
Minutes : 0
Seconds : 12
Milliseconds : 398
Ticks : 123980891
TotalDays : 0.00014349640162037
TotalHours : 0.00344391363888889
TotalMinutes : 0.206634818333333
TotalSeconds : 12.3980891
TotalMilliseconds : 12398.0891
What could be the problem? I'm working with PowerShell 5:
PS F:\> get-host | select-object version
Version
-------
5.1.18362.1801
PS F:\>
But that also takes 12 seconds to compute:
PS F:\> measure-command { get-host | select-object version }
Days : 0
Hours : 0
Minutes : 0
Seconds : 12
Milliseconds : 442
Ticks : 124426798
TotalDays : 0.000144012497685185
TotalHours : 0.00345629994444444
TotalMinutes : 0.207377996666667
TotalSeconds : 12.4426798
TotalMilliseconds : 12442.6798
I believe that it's because of the antivirus software. It might be loading some antivirus related modules before the PowerShell module. One way to confirm this is by running the following command in cmd.
powershell.exe -c "Write-Host $PID;Start-Sleep -s 30"
This will print the PID associated with the PowerShell process and sleep for 30 seconds, Meantime open another PowerShell session and run
Get-Process | where {$_.Id -eq <PASTE_YOUR_PID>} | select -ExpandProperty modules
This will list the modules that have been loaded by the PowerShell process. If you are seeing your antivirus related DLLs in the list, most likely that causing the slow down.