Find Files older than 6 months and then ZIP the Files

Kelly Garcia
Kelly Garcia used Ask the Experts™
on
Hi All,

I have the script below:

$pathname = "C:\Users\kelly.garcia"
  $files = Get-ChildItem $pathname -Recurse -File | 
	Where-Object LastAccessTime -le (Get-date).AddMonths(-1)
  
		foreach ($f in $files)
		{
			$Name = $f.name
			#Compress-Archive $f -DestinationPath $pathname\$Name.zip
		}

Open in new window


how do I tell the script to find files only files that are equal to or greater than 1gb?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Kelly GarciaSenior Systems Administrator

Author

Commented:
also when I run the script I get this error:

Compress-Archive : The path '2013-09-18 10.57.31.jpg' either does not exist or is not a valid file system path.
At line:4 char:1
+ Compress-Archive $f -DestinationPath $pathname\$Name.zip
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (2013-09-18 10.57.31.jpg:String) [Compress-Archive], InvalidOperationException
    + FullyQualifiedErrorId : ArchiveCmdletPathNotFound,Compress-Archive

$pathname = "C:\Users\Kelly.garcia"
  $files = Get-ChildItem $pathname -Recurse -File | 
	Where-Object LastAccessTime -le (Get-date).AddMonths(-1)
  
		foreach ($f in $files)
		{
			$Name = $f.name
			Compress-Archive $f -DestinationPath $pathname\$Name.zip
		}

Open in new window

PowerShell Developer
Top Expert 2010
Commented:
Another filter term:
$pathname = "C:\Users\kabir.uddin"
$files = Get-ChildItem $pathname -Recurse -File | 
    Where-Object { $_.LastAccessTime -le (Get-date).AddMonths(-1) -and $_.Length -ge 1GB }

foreach ($f in $files) {
    $Name = $f.name
    #Compress-Archive $f -DestinationPath $path\$Name.zip
}

Open in new window

It came up in the last thread, but Compress-Archive has a built-in limit of 2GB. We'll need to use 7-zip (or something similar) to compress files of this size.
Kelly GarciaSenior Systems Administrator

Author

Commented:
for testing I want find files just over a 1mb how do I input that, do I just type 1mb where -ge 1gb is?
Chris DentPowerShell Developer
Top Expert 2010

Commented:
That's correct, yes.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial