Reputation: 3
On an old server we have millions of log files. These log files are part of an integration framework we are running that has never been cleaned up. There are approximately 1.8 million XML log files spread out over 3000 directories.
The folders have the following structure:
D:\Program Files\<Our company name>\<Integration framework version [5 folders]>\Environment\<Customer Name [20 folders]>\<Integration name [Between 1-15 folders]>\<Release version [1-10 folders]>\XmlLogs\<Date [Hundreds of folders]>\logname.xml
Examples:
D:\Program Files\Company\Company Integration 4.5.5\Environment\Company A\GenericEmailer\Release1.0.0.I1\XmlLogs\01-01-2014\logname.xml
D:\Program Files\Company\Company Integration 4.5.6\Environment\Company B\GlobalEmailer\Release1.2.3.I2\XmlLogs\01-01-2019\logname.xml
My plan was searching for all the XmlLogs directories and emptying those directories, but whenever I do a Get-ChildItem the whole server freezes and never outputs the results.
Get-ChildItem -Directory "D:\Program Files\Company\Company Integration 4.5.6\Environment\Company A\" -Recurse -Name -Include "XmlLogs"
What is the right way to do this and also delete all the log files?
Upvotes: 0
Views: 284
Reputation: 17462
May be you can try this (modifiy the like like you want or use -match operator +regex expression)
Get-ChildItem "C:\Program Files" -directory -recurse | % {
if ($_.fullname -like '*\XmlLogs\*')
{
Get-ChildItem $_.FullName -Recurse -file -filter "*.xml" | Remove-Item -Force -WhatIf
}
}
Note 1 : To really remove you must remove "-whatif" option in my example
Note 2 : For better performance you can use 'D:\Program Files\Company' if the company name doesn't change.
Upvotes: 1