|
| 1 | +--- |
| 2 | +external help file: PSScriptTools-help.xml |
| 3 | +Module Name: PSScriptTools |
| 4 | +online version: |
| 5 | +schema: 2.0.0 |
| 6 | +--- |
| 7 | + |
| 8 | +# Get-LastModifiedFile |
| 9 | + |
| 10 | +## SYNOPSIS |
| 11 | + |
| 12 | +Get files based on last modified data. |
| 13 | + |
| 14 | +## SYNTAX |
| 15 | + |
| 16 | +```yaml |
| 17 | +Get-LastModifiedFile [[-Filter] <String>] [[-Path] <String>] |
| 18 | +[-Interval <String>] [-IntervalCount <Int32>] [-Recurse] [<CommonParameters>] |
| 19 | +``` |
| 20 | + |
| 21 | +## DESCRIPTION |
| 22 | + |
| 23 | +This command is designed to make it easier to identify last modified files. You can specify by an interval such as 3 months or 24 hours. |
| 24 | + |
| 25 | +## EXAMPLES |
| 26 | + |
| 27 | +### Example 1 |
| 28 | + |
| 29 | +```powershell |
| 30 | +PS C:\> Get-LastModifiedFile -Path c:\work |
| 31 | +
|
| 32 | + Directory: C:\work |
| 33 | +
|
| 34 | +Mode LastWriteTime Length Name |
| 35 | +---- ------------- ------ ---- |
| 36 | +-a--- 11/30/2021 1:52 PM 2010 a.txt |
| 37 | +-a--- 11/30/2021 1:52 PM 5640 b.txt |
| 38 | +``` |
| 39 | + |
| 40 | +The default behavior is to find all files modified in the last 24 hours. |
| 41 | + |
| 42 | +### Example 2 |
| 43 | + |
| 44 | +```powershell |
| 45 | +PS C:\> Get-LastModifiedFile -Path c:\scripts -Filter *.ps1 -Interval Months -IntervalCount 6 |
| 46 | +
|
| 47 | + Directory: C:\Scripts |
| 48 | +
|
| 49 | +Mode LastWriteTime Length Name |
| 50 | +---- ------------- ------ ---- |
| 51 | +-a--- 11/19/2021 2:36 PM 1434 calendar-prompt.ps1 |
| 52 | +-a--- 10/11/2021 11:26 AM 1376 ChangeOSCaption.ps1 |
| 53 | +-a--- 8/27/2021 8:06 AM 2754 Check-ModuleUpdate.ps1 |
| 54 | +-a--- 9/17/2021 9:23 AM 1822 CleanJobs.ps1 |
| 55 | +-a--- 7/14/2021 10:36 AM 436 Clear-Win11Recommended.ps1 |
| 56 | +-a--- 10/18/2021 5:24 PM 5893 ComingSoon.ps1 |
| 57 | +-a--- 10/25/2021 5:23 PM 4966 Configure-PSVirtualMachine.ps1 |
| 58 | +... |
| 59 | +``` |
| 60 | + |
| 61 | +Get all .ps1 files in C:\Scripts that have been modified in the last 6 months. |
| 62 | + |
| 63 | +## PARAMETERS |
| 64 | + |
| 65 | +### -Filter |
| 66 | + |
| 67 | +Specify a file filter like *.ps1. |
| 68 | + |
| 69 | +```yaml |
| 70 | +Type: String |
| 71 | +Parameter Sets: (All) |
| 72 | +Aliases: |
| 73 | + |
| 74 | +Required: False |
| 75 | +Position: 0 |
| 76 | +Default value: None |
| 77 | +Accept pipeline input: False |
| 78 | +Accept wildcard characters: False |
| 79 | +``` |
| 80 | +
|
| 81 | +### -Interval |
| 82 | +
|
| 83 | +Specify the search interval based on the last write time. |
| 84 | +
|
| 85 | +```yaml |
| 86 | +Type: String |
| 87 | +Parameter Sets: (All) |
| 88 | +Aliases: |
| 89 | +Accepted values: Hours, Minutes, Days, Months, Years |
| 90 | + |
| 91 | +Required: False |
| 92 | +Position: Named |
| 93 | +Default value: Hours |
| 94 | +Accept pipeline input: False |
| 95 | +Accept wildcard characters: False |
| 96 | +``` |
| 97 | +
|
| 98 | +### -IntervalCount |
| 99 | +
|
| 100 | +Specify the number of intervals. |
| 101 | +
|
| 102 | +```yaml |
| 103 | +Type: Int32 |
| 104 | +Parameter Sets: (All) |
| 105 | +Aliases: ic |
| 106 | + |
| 107 | +Required: False |
| 108 | +Position: Named |
| 109 | +Default value: 24 |
| 110 | +Accept pipeline input: False |
| 111 | +Accept wildcard characters: False |
| 112 | +``` |
| 113 | +
|
| 114 | +### -Path |
| 115 | +
|
| 116 | +Specify the folder to search. |
| 117 | +
|
| 118 | +```yaml |
| 119 | +Type: String |
| 120 | +Parameter Sets: (All) |
| 121 | +Aliases: |
| 122 | + |
| 123 | +Required: False |
| 124 | +Position: 1 |
| 125 | +Default value: current location |
| 126 | +Accept pipeline input: False |
| 127 | +Accept wildcard characters: False |
| 128 | +``` |
| 129 | +
|
| 130 | +### -Recurse |
| 131 | +
|
| 132 | +Recurse from the specified path. |
| 133 | +
|
| 134 | +```yaml |
| 135 | +Type: SwitchParameter |
| 136 | +Parameter Sets: (All) |
| 137 | +Aliases: |
| 138 | + |
| 139 | +Required: False |
| 140 | +Position: Named |
| 141 | +Default value: None |
| 142 | +Accept pipeline input: False |
| 143 | +Accept wildcard characters: False |
| 144 | +``` |
| 145 | +
|
| 146 | +### CommonParameters |
| 147 | +
|
| 148 | +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). |
| 149 | +
|
| 150 | +## INPUTS |
| 151 | +
|
| 152 | +### None |
| 153 | +
|
| 154 | +## OUTPUTS |
| 155 | +
|
| 156 | +### System.IO.FileInfo |
| 157 | +
|
| 158 | +## NOTES |
| 159 | +
|
| 160 | +This command was first described at https://jdhitsolutions.com/blog/powershell/8622/finding-modified-files-with-powershell/ |
| 161 | +
|
| 162 | +Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/ |
| 163 | +
|
| 164 | +## RELATED LINKS |
| 165 | +
|
| 166 | +[Get-ChildItem]() |
| 167 | +
|
| 168 | +[Get-DirectoryInfo](Get-DirectoryInfo.md) |
| 169 | +
|
| 170 | +[Get-FolderSizeInfo](Get-FolderSizeInfo.md) |
0 commit comments