Skip to content

Instantly share code, notes, and snippets.

@Graham-Beer
Created February 13, 2019 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Graham-Beer/2f306f80b47f1deb83b37f39c7973e18 to your computer and use it in GitHub Desktop.
Save Graham-Beer/2f306f80b47f1deb83b37f39c7973e18 to your computer and use it in GitHub Desktop.
function Invoke-FileArchive {
param (
[Parameter(
Mandatory,
Position = 0,
ValueFromPipeline,
ValueFromPipelineByPropertyName
)]
[Alias('FullName')]
[System.IO.FileSystemInfo[]] $Path,
[Parameter(Mandatory, Position = 1)]
[String] $Destination,
[Parameter(Position = 2)]
[TimeSpan] $OlderThan = '1.0:0:0'
)
process {
foreach ($file in $Path) {
if ($file -is [System.IO.FileInfo]) {
$file |
Where-Object {
$_.LastWriteTime -lt (Get-Date).Add($OlderThan.Negate())
} | Move-Item -Destination $Destination
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment