I'd like to create a script that helps to copy files modified in a time range. I would like to leave the $EndDate parameter as optional and in such-case, I'd like the script to use today's date as Default.
Below is the Script:
param (
[Parameter(Mandatory=$True)]
[string]$Path,
[Parameter(Mandatory=$True)]
[string]$targetDir,
[Parameter(Mandatory=$True)]
[string]$BeginDate,
[Parameter(Mandatory=$False)]
[string]$EndDate,
[switch]$force
)
Get-ChildItem -Path $Path -Recurse | Where-Object {$_.LastWriteTime -gt $BeginDate -and $_.LastWriteTime -lt $EndDate }| cp -Destination $targetDir -Force