Find Files older than 6 months and then ZIP the Files

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?
Kelly GarciaSenior Systems AdministratorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kelly GarciaSenior Systems AdministratorAuthor 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

0
Chris DentPowerShell DeveloperCommented:
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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kelly GarciaSenior Systems AdministratorAuthor 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?
0
Chris DentPowerShell DeveloperCommented:
That's correct, yes.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.