You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Get-FolderAge.ps1
+60-15Lines changed: 60 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
<#PSScriptInfo
2
2
3
-
.VERSION 1.1
3
+
.VERSION 1.2
4
4
.GUID c9788cc2-d4af-4219-bf7d-8dd8fa89584f
5
5
.AUTHOR Igor Iric, iricigor@gmail.com, https://github.com/iricigor
6
6
.COMPANYNAME
@@ -12,7 +12,7 @@
12
12
.EXTERNALMODULEDEPENDENCIES
13
13
.REQUIREDSCRIPTS
14
14
.EXTERNALSCRIPTDEPENDENCIES
15
-
.RELEASENOTES Added -Exclude and -Threads parameters, for more info see https://github.com/iricigor/GetFolderAge/blob/master/ReleaseNotes.md
15
+
.RELEASENOTES Added restartable script functionality and alias, bug fixes for append and threads issues, for more info see https://github.com/iricigor/GetFolderAge/blob/master/ReleaseNotes.md
16
16
.DESCRIPTION Get-FolderAge returns `LastModifiedDate` for a specified folder(s) and if folders were modified after a specified cut-off date.
17
17
18
18
#>
@@ -103,8 +103,11 @@ function Global:Get-FolderAge {
103
103
If both CutOffTime and CutOffDays specified, the script will throw a warning.
104
104
105
105
.PARAMETEROutputFile
106
-
A string specifying file name which will be used for output. If not specified, there will be no file output generated.
106
+
A string specifying file name which will be used for output in addition to screen (or pipeline) output.
107
107
This is especially useful for long running commands. Each folder as soon as processed will be stored in the file.
108
+
This can be also used for restarting the script, if it gets interrupted before it finishes all folders.
109
+
Just specify the same input and output files, and script will skip already processed folders!
110
+
If this parameter is not specified, there will be no file output generated.
108
111
109
112
.PARAMETERExclude
110
113
Specifies, as a string array, an folder names that this cmdlet excludes in the search operation.
@@ -163,7 +166,8 @@ function Global:Get-FolderAge {
163
166
164
167
[parameter(Mandatory=$false)] [string[]]$Exclude,
165
168
166
-
[parameter(Mandatory=$false)] [int]$Threads=0,
169
+
[parameter(Mandatory=$false)]
170
+
[ValidateRange(0,50)] [int]$Threads=0,
167
171
168
172
#
169
173
# Switches
@@ -185,10 +189,10 @@ function Global:Get-FolderAge {

6
7
7
-
PowerShell script which checks for last modified date _(LastWriteTime)_ for large number of folders.
8
+
PowerShell script which checks for last modified date _(LastWriteTime)_ for a large number of folders.
8
9
It checks recursively for all files and folders inside taking into account potential errors (inaccessible files, too long paths, etc.).
9
10
10
11
Running a script itself will just import (i.e. create) new commandlet **`Get-FolderAge`** in your session.
11
12
It will not do any checks.
12
13
You can afterwards run this commandlet with proper parameters as in examples below.
13
14
14
15
Running commandlet with specifying only a folder name will return last modification time of that folder.
15
-
If you specify `-CutOffDate` (or `-CutoffDays`) script will determine if folder was modified after that time. It will exit folder search as soon as it finds modified file or folder.
16
+
If you specify `-CutOffDate` (or `-CutoffDays`) script will determine if the folder was modified after that time. It will exit folder search as soon as it finds a modified file or folder.
16
17
17
-
Commandlet can be run in un-attended mode also with file output using `-OutputFileName` parameter. Output format is comma-separated value, so file extension should be `.csv`.
18
+
Commandlet can be run in unattended mode also with file output using `-OutputFileName` parameter. Output format is comma-separated value, so file extension should be `.csv`.
18
19
19
20
Technical explanation of LastModifiedDate can be seen in [this archived copy](https://web.archive.org/web/20110604022236/http://support.microsoft.com/kb/299648) of Microsoft knowledge base article.
20
21
21
22
## Download
22
23
23
-
You can download this script in couple of ways listed below. Execute a script after downloading it (no admin rights needed) to add commandlet `Get-FolderAge` to your session.
24
+
You can download this script in a couple of ways listed below. Execute a script after downloading it (no admin rights needed) to add commandlet `Get-FolderAge` to your session.
24
25
25
26
-**Download from GitHub:**
26
27
You can see online latest script version at this [link](https://github.com/iricigor/GetFolderAge/blob/master/Get-FolderAge.ps1).
27
-
Raw PS1 file can be downloaded from [here](https://raw.githubusercontent.com/iricigor/GetFolderAge/master/Get-FolderAge.ps1).
28
+
The raw PS1 file can be downloaded from [here](https://raw.githubusercontent.com/iricigor/GetFolderAge/master/Get-FolderAge.ps1).
28
29
29
30
-**Clone repository:**
30
-
If you want to see entire GitHub repository, just clone it
31
+
If you want to see the entire GitHub repository, just clone it
@@ -63,41 +64,49 @@ Tests if folders listed in specified input file (one folder per line) are modifi
63
64
Input can be specified in three ways:
64
65
65
66
* parameter `-FolderName`_(default parameter, can be omitted)_ followed by string or an array of strings specifying paths to be checked
66
-
* via pipeline - the same values as above can be passed via pipeline, see example with `Get-ChildItem`
67
+
* via pipeline - the same values as above can be passed via pipeline, see the example with `Get-ChildItem`
67
68
* parameter `-InputFile` - a file specifying folders to be processed, one folder per line
68
69
69
70

70
71
71
72
### Cut-off Date explanation
72
73
73
74
Cut-off date represents the point in time for which we want to know if a folder was modified after.
74
-
Usually this is the date when last copy or backup or sync was performed on given folder.
75
+
Usually, this is the date when last copy or backup or sync was performed on the given folder.
75
76
76
77
It can be specified as:
77
78
78
79
* PowerShell [DateTime] object, i.e. the value returned by Get-Date command
79
-
*Integer number representing days since last cut-off date (easier, but less precise)
80
+
*An integer number representing days since last cut-off date (easier, but less precise)
80
81
81
82
### Output format
82
83
83
-
Commandlet outputs array of FolderAgeResult objects. Each object contain these properties:
84
+
Commandlet outputs array of objects. Each object contains these properties:
84
85
85
86
*[string]`Path` - as specified in input parameters (or obtained subfolder names)
86
87
*[datetime]`LastWriteTime` - latest write time for all items inside of the folder
87
-
*[bool]`Modified` - if folder was modified since last cut-off date (or null if date not given)
88
+
*[bool]`Modified` - if the folder was modified since last cut-off date (or null if date not given)
88
89
89
90
It also outputs diagnostic/statistics info:
90
91
91
-
*[bool]`Confident` - if Modified return value is confident result, in case commandlet is called with QuickTest switch, return value for Modified might not be correct.
92
+
*[bool]`Confident` - if Modified return value is a confident result; in case commandlet is called with QuickTest switch, return value for Modified might not be correct.
92
93
*[int]`TotalFiles` - total number of files and directories scanned
93
94
*[int]`TotalFolders` - total number of directories scanned
94
-
*[string]`LastItem` - item with latest timestamp found (note that this might not ber really the latest modified file. If this timestamp is newer than CutOffDate, commandlet will not search further.
95
+
*[string]`LastItem` - an item with the latest timestamp found (note that this might not be really the latest modified file. If this timestamp is newer than CutOffDate, commandlet will not search further.
95
96
*[int]`Depth` - total depth of scanned folders relative to initial folder. If QuickTest, then it will be 1, regardless of real depth. If CutOffDate specified, it might not go to full depth, so this number will be smaller than full depth.
96
97
*[decimal]`ElapsedSeconds` - time spent in checking the folder
97
98
*[datetime]`FinishTime` - date and time when folder check was completed
98
-
*[bool]`Errors` - indicate if command encountered errors during its execution (i.e. Access Denied on part of the files)
99
+
*[bool]`Errors` - indicate if command encountered errors during its execution (i.e. Access Denied on some file)
99
100
*[string]`LastError` - text of the last encountered error
100
101
102
+
### Restartable script
103
+
104
+
Parameter `-OutputFile` specifies where output data is stored on the disk.
105
+
If the script is interrupted before finishing, you can restart it without a need to process same folders again.
106
+
Just specify the same `-OutputFile` and `-InputFile` and script will skip already processed folders!
107
+
108
+
This is especially useful for long running scripts.
109
+
101
110
## Build status
102
111
103
112
Each commit or PR to master is checked on [Azure DevOps](https://azure.microsoft.com/en-us/services/devops/)[Pipelines](https://azure.microsoft.com/en-us/services/devops/pipelines/) on two build systems:
0 commit comments