Last active
March 17, 2020 15:27
-
-
Save codaamok/e22cb9e7f357239c49f8ceb5a5791b5a to your computer and use it in GitHub Desktop.
17/03/2020 update: thanks @indented-automation. Snippet to compare various filter options. Linked here: https://www.cookadam.co.uk/get-cmunusedsources
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $winFiles = Get-ChildItem c:\windows -Recurse -ErrorAction SilentlyContinue | |
| $commands = @{ | |
| 'Where-Object' = { | |
| $exeFiles = $winFiles | Where-Object { $_.Extension -eq ".exe" } | |
| } | |
| 'Where-Object (no script block)' = { | |
| $exeFiles = $winFiles | Where-Object Extension -eq ".exe" | |
| } | |
| '.Where' = { | |
| $exeFiles = $winFiles.Where{ $_.Extension -eq ".exe" } | |
| } | |
| 'DataTable' = { | |
| $fileTable = New-Object System.Data.DataTable | |
| $fileTable.TableName = "AllMuhFiles" | |
| [void]$fileTable.Columns.Add("FileName") | |
| [void]$fileTable.Columns.Add("Parent") | |
| [void]$fileTable.Columns.Add("Extension") | |
| [void]$fileTable.Columns.Add("IsInf") | |
| ForEach($file in $winFiles) { | |
| [void]$fileTable.Rows.Add($file.Name, $file.Parent, $file.Extension) | |
| } | |
| $exeFiles = $fileTable.Select("Extension like '.exe'") | |
| } | |
| 'foreach' = { | |
| $exefiles = foreach ($file in $winFiles) { | |
| if ($file.Extension -eq '.exe') { | |
| $file | |
| } | |
| } | |
| } | |
| } | |
| $commands.Keys | ForEach-Object { | |
| $testName = $_ | |
| 1..3 | ForEach-Object { | |
| [PSCustomObject]@{ | |
| TestName = $testName | |
| Attempt = $_ | |
| ElapsedMS = (Measure-Command -Expression $commands[$testName]).TotalMilliseconds | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment