Skip to content

Instantly share code, notes, and snippets.

@sba923
Last active January 31, 2024 14:49
Show Gist options
  • Save sba923/0395f7fd716d87cf92d52946b10a30b7 to your computer and use it in GitHub Desktop.
Save sba923/0395f7fd716d87cf92d52946b10a30b7 to your computer and use it in GitHub Desktop.
Helper for "gci ... | mtime x" PowerShell equivalent to "find ... -mtime x"
# this is one of Stéphane BARIZIEN's public domain scripts
# the most recent version can be found at:
# https://gist.github.com/sba923/0395f7fd716d87cf92d52946b10a30b7#file-mtime-ps1
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline)]
$Item,
[Parameter(Position=0)][int] $Days
)
Begin
{
#TODO match find's rounding scheme (e.g. for -mtime 0's behavior)
$timeboundary = [datetime]::Now.AddDays($Days)
}
Process {
if ($Item.LastWriteTime -ge $timeboundary)
{
$Item
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment