Skip to content

Instantly share code, notes, and snippets.

@MaxAnderson95
Created November 30, 2022 19:01
Show Gist options
  • Save MaxAnderson95/dde46af43c4c64234122f7506af60af7 to your computer and use it in GitHub Desktop.
Save MaxAnderson95/dde46af43c4c64234122f7506af60af7 to your computer and use it in GitHub Desktop.
A PowerShell function to add to your profile that filters file and folder objects for ones created on today's calendar date

Code

Function Today {
    [CmdletBinding()]
    Param (
        [Parameter(ValueFromPipeline = $True)]
        [System.IO.FileInfo[]]$Files,

        [Parameter(ValueFromPipeline = $True)]
        [System.IO.DirectoryInfo[]]$Folders
    )

    Process {
        ($Files + $Folders) | Where-Object { $_.CreationTime -gt (Get-Date -Hour 0 -Minute 0 -Second 0) }
    }
}

Usage

#Get Current Time
~\Desktop > Get-Date

Wednesday, November 30, 2022 1:59:59 PM

Before

~\Desktop > Get-ChildItem
    Directory: C:\Users\mander\Desktop

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----          11/30/2022  1:56 PM                newfolder
d----          11/1/2022   8:00 AM                oldfolder
la---          11/30/2022  1:56 PM              0 newfile
la---          11/1/2022   8:00 AM              0 oldfile

After

~\Desktop > Get-ChildItem | Today

    Directory: C:\Users\mander\Desktop

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----          11/30/2022  1:56 PM                newfolder
la---          11/30/2022  1:56 PM              0 newfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment