Avatar of Kelly Garcia
Kelly Garcia
Flag for United Kingdom of Great Britain and Northern Ireland asked on

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?
PowershellScripting Languages

Avatar of undefined
Last Comment
Chris Dent

8/22/2022 - Mon
Kelly Garcia

ASKER
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

ASKER CERTIFIED SOLUTION
Chris Dent

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Kelly Garcia

ASKER
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 Dent

That's correct, yes.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy