Link to home
Start Free TrialLog in
Avatar of Kelly Garcia
Kelly GarciaFlag 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?
Avatar of Kelly Garcia
Kelly Garcia
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
for testing I want find files just over a 1mb how do I input that, do I just type 1mb where -ge 1gb is?
That's correct, yes.