Skip to content

Instantly share code, notes, and snippets.

@pjmagee
Created May 28, 2013 01:25
Show Gist options
  • Select an option

  • Save pjmagee/5659973 to your computer and use it in GitHub Desktop.

Select an option

Save pjmagee/5659973 to your computer and use it in GitHub Desktop.
Sets the creation date to a set of folders in directory based on the current date.
# sets the folder creation date to the specified date variable
# version 0.0.1
# author: Patrick Magee
#######################
$choice = ""
$dir = ""
$date = [datetime]::Today
while ($choice -notmatch "[y|n]") {
$choice = Read-Host "Set creation date? (Y/N)"
if($choice -eq "y") {
while(-not [System.IO.Directory]::Exists($dir)) {
$dir = Read-Host "Enter valid directory. e.g 'D:\videos\Movies'"
}
Write-Host "Listing directories created in the past..." -ForegroundColor Green
$total = (Get-ChildItem $dir | Where-Object { $_.CreationTime -lt $date }).Count
Get-ChildItem $dir | Where-Object {
$_.CreationTime -lt $date
} | ForEach-Object {
Write-Host ('{0} ({1})' -f $_.Name, $_.CreationTime) -ForegroundColor Red
}
$choice = ""
While ($choice -notmatch "[y|n]") {
$choice = read-host "Are you sure you want to set the creation date on $total items to $date" + "? (Y/N)"
}
if($choice -eq "y"){
Get-ChildItem $dir | where { $_.CreationTime -lt $date } | ForEach-Object { $_.CreationTime = $date }
Write-Host 'Complete.' -ForegroundColor Red
}
else {
Write-Host "Cancelled." -ForegroundColor Red
}
}
else {
Write-Host "Cancelled." -ForegroundColor Red
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment