We help IT Professionals succeed at work.

Find Files older than 6 months and then ZIP the Files

212 Views
Last Modified: 2018-02-15
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

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
CERTIFIED EXPERT
Top Expert 2010
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
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
CERTIFIED EXPERT
Top Expert 2010

Commented:
That's correct, yes.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions