Skip to content

Commit c696014

Browse files
committed
feat(Get-LastUsedItem): update function to stream output for reduced memory usage
* Refactored `Get-LastUsedItem` to directly select properties from `Get-ChildItem`, eliminating the need for an intermediate variable. * Updated example in documentation to reflect CSV export instead of Excel for more reliable output when dealing with large datasets.
1 parent 7be5b8a commit c696014

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

modules/AdminToolbox.FileManagement/ChangeLog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,5 @@
5050
* **1.18.0.1** CI Maintenance Release
5151
* **1.18.0.11** CI Maintenance Release
5252
* **1.19.0.0** Add Get-LastUsedItem function
53-
* **1.19.0.1** CI Maintenance Release
53+
* **1.19.0.1** CI Maintenance Release
54+
* **1.19.0.2** Update Get-LastUsedItem to stream output instead of loading a variable, so it uses less memory.

modules/AdminToolbox.FileManagement/Public/Get-LastUsedItem.ps1

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
The parent directory path to recurse.
77
88
.EXAMPLE
9-
Get-LastUsedItem -Path "C:\Temp" | Export-Excel .\lastused.xlsx
9+
Get-LastUsedItem -Path "C:\Temp" | Export-csv .\lastused.csv -NoTypeInformation -append
1010
1111
.Notes
1212
Returns a list of custom objects with item name, full path, container status, and timestamps.
@@ -20,17 +20,6 @@ function Get-LastUsedItem {
2020
[string]$Path
2121
)
2222

23-
$items = Get-ChildItem -Path $Path -Recurse -Force
23+
Get-ChildItem -Path $Path -Recurse -Force | Select-Object name, directoryname, fullname, psiscontainer, lastwritetime, creationtime, lastaccesstime
2424

25-
foreach ($item in $items) {
26-
[pscustomobject]@{
27-
Item = $item.Name
28-
DirectoryName = $item.DirectoryName
29-
FullName = $item.FullName
30-
PSIsContainer = $item.PSIsContainer
31-
LastWriteTime = $item.LastWriteTime
32-
CreationTime = $item.CreationTime
33-
LastAccessTime = $item.LastAccessTime
34-
}
35-
}
3625
}

0 commit comments

Comments
 (0)