Skip to content

Instantly share code, notes, and snippets.

@star-crossed
Created May 21, 2018 19:58
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 star-crossed/66ef923f43b3f773c908e30e73c144b0 to your computer and use it in GitHub Desktop.
Save star-crossed/66ef923f43b3f773c908e30e73c144b0 to your computer and use it in GitHub Desktop.
A PowerShell script to recursively zip all files that were last modified on or after the supplied start date.
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true, HelpMessage = "This is the date used for filtering.")]
[string]$StartDate
)
$ParsedDate = [System.DateTime]$StartDate
$CurrentPath = (Get-Item -Path ".\").FullName
$CurrentFolder = (Get-Item -Path ".\").Name
Get-ChildItem -Path . -Recurse -Attributes !D | Where-Object {
$_.LastWriteTime -ge $ParsedDate -and -not ($_.Name -eq "New-LastModifiedZip.ps1")
} | ForEach-Object {
$thisFileName = $_.FullName.Replace("$CurrentPath\", "")
Out-File -FilePath ".\$CurrentFolder.txt" -Append -Encoding ascii -InputObject $thisFileName
}
& "C:\Program Files\7-Zip\7z.exe" a -tzip -scsWIN "$CurrentFolder.zip" "`@$CurrentFolder.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment