Powershell script pull files dated earlier 2017


I need to create a powershell script to pull files and folders dated earlier than 2017, windows server 2019

Location: C:\stofs01

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,435 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 32,531 Reputation points

    File and folders have 3 date properties. CreationTime, LastWriteTime, LastAccessTime

    Here's an example using LastWriteTime.

    $targetDate = get-date -Year 2017 -Month 7 -day 1
    get-childitem -path c:\temp -recurse | Where-Object {$_.LastWriteTime -lt $targetDate}
    0 comments No comments