Created
August 27, 2019 21:23
-
-
Save howellcc/62e9d58d0091ffcdc3632c3aaa001a35 to your computer and use it in GitHub Desktop.
Create Backdated test files
This file contains 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
# This script creates a series of text files and back-dates the createTime, modifiedTime and accessedTime. | |
# I wrote it to test deleting of files X number of days old. It creates the following files: | |
# 1days.txt - which is 1 day old | |
# 2days.txt - which is 2 days old | |
# .... you get the idea. | |
$destfolder = "C:\Users\{username}\temp"; | |
$numFilesToCreate = 500; | |
For($i=1; $i -le $numFilesToCreate; $i++){ | |
$currentfile = $destfolder + '\' + $i + 'days.txt'; | |
#Create File | |
Set-Content -Path $currentfile -Value 'test string' | |
#Get File we just created | |
$file = Get-Item $currentfile; | |
#Reset Attributes | |
$file.LastWriteTime = (Get-Date).AddDays($i * -1); | |
$file.LastAccessTime = (Get-Date).AddDays($i * -1); | |
$file.CreationTime = (Get-Date).AddDays($i * -1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment