UNCLASSIFIED

Skip to content
Snippets Groups Projects
Commit ff09f994 authored by Joshua Parsons's avatar Joshua Parsons
Browse files

gensite

parent cf56fae7
No related merge requests found
Pipeline #117907 passed with stages
in 12 seconds
......@@ -96,39 +96,41 @@ In order to maximize efficiency in your PowerShell code, always filter before so
.Low efficiency command
[source,powershell]
----
PS C:\> Get-Process | Sort-Object -Property Id | Select-Object Name, Id
PS C:\> Get-ChildItem -Path C:\Windows\System32 -Recurse -ErrorAction SilentlyContinue | Sort-Object | Select-Object -Property Name
PS C:\> Measure-Command {Get-ChildItem -Path C:\Windows\System32 -Recurse -ErrorAction SilentlyContinue | Sort-Object | Select-Object -Property Name}
PS C:\> Measure-Command { Get-Process | Sort-Object -Property Id | Select-Object Name, Id }
Days : 0
Hours : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 22
Ticks : 227313
TotalDays : 2.6309375E-07
TotalHours : 6.31425E-06
TotalMinutes : 0.000378855
TotalSeconds : 0.0227313
TotalMilliseconds : 22.7313
Seconds : 2
Milliseconds : 111
Ticks : 21111244
TotalDays : 2.44343101851852E-05
TotalHours : 0.000586423444444444
TotalMinutes : 0.0351854066666667
TotalSeconds : 2.1111244
TotalMilliseconds : 2111.1244
----
.Higher efficiency command
[source,powershell]
----
PS C:\> Get-Process | Select-Object Name, Id | Sort-Object -Property Id
PS C:\> Get-ChildItem -Path C:\Windows\System32 -Recurse -ErrorAction SilentlyContinue | Select-Object -Property Name | Sort-Object
PS C:\> Measure-Command {Get-ChildItem -Path C:\Windows\System32 -Recurse -ErrorAction SilentlyContinue | Select-Object -Property Name | Sort-Object}
PS C:\> Measure-Command { Get-Process | Select-Object Name, Id | Sort-Object -Property Id }
Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 16
Ticks : 166182
TotalDays : 1.92340277777778E-07
TotalHours : 4.61616666666667E-06
TotalMinutes : 0.00027697
TotalSeconds : 0.0166182
TotalMilliseconds : 16.6182
Seconds : 1
Milliseconds : 37
Ticks : 10370187
TotalDays : 1.200253125E-05
TotalHours : 0.00028806075
TotalMinutes : 0.017283645
TotalSeconds : 1.0370187
TotalMilliseconds : 1037.0187
----
The performance difference seems minor in the above examples. However, when working with commands that gather data from multiple machines, or over the network, the difference in efficiency could be a significant factor in time to complete.
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment