Functions/Set-ItemDateTime.ps1
<#
.SYNOPSIS Updates the CreationTime and LastWriteTime properties of an item (Directory and/or File) .DESCRIPTION Updates the CreationTime and LastWriteTime properties of an item (Directory and/or File) .EXAMPLE Set-ItemDateTime -Path 'C:\Temp\MyNewBuild' -Recurse .EXAMPLE Set-ItemDateTime -Path 'C:\Temp\MyNewBuild' -Recurse -RoundToTenMinutes #> Function Set-ItemDateTime { [CmdletBinding()] Param( [Parameter(Mandatory=$true)] [string] $Path, [datetime] $DateTime, [switch] $Recurse, [switch] $RoundToTenMinutes, [switch] $FilesOnly ) if($DateTime){ $dt = $DateTime } else { $dt = Get-Date } if($RoundToTenMinutes){ $dt = $dt.AddMinutes(-($dt.Minute % 10)) $dt = $dt.AddSeconds(-($dt.Second % 60)) } if($FilesOnly){ $items = Get-Childitem $Path -Recurse:$Recurse -File } else { $items = Get-Childitem $Path -Recurse:$Recurse } foreach ($item in $items) { $item.CreationTime = $dt $item.LastWriteTime = $dt } } Export-ModuleMember -Function Set-ItemDateTime |