Jump to content

Delete 0kb files from specified path from text file


Recommended Posts

Posted

I can use this script to delete 0 kb files from a specified path. get-childItem "PathToFiles" | where {$_.length -eq 0} | remove-Item

 

How can i run this on multiple PC's in a text file (list.txt)?

 

The contents of text file would be:

 

pc1

pc2

 

or

 

\\PC1\c$\files\

\\PC2\c$\files\

Posted

If you have the list in the second format then you should be able to do something like this:

 

 
Get-content -path C:\file.txt -pipelinevariable folder| foreach-object { Get-ChildItem $folder | where { $_.length -eq 0} | remove-item -confirm $false} 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...