I know there is code review for 'speed up' exists, but I also need to 'fix' problem of my script.
I migrated from Command Prompt(.bat
) to Powershell(.ps1
) because I think Command Prompt is hard to make script for complex things. I've heard that Powershell may have some overhead than Command Prompt, but if it is fast enough, I don't care.
Here is link for two files, sdn.old.bat
and sdn.new.ps1
. I put them in paste site because those are long enough.
Here is my problem.
This part takes a very long time to run.
$logs_loc = @(
"$Env:LocalAppdata"
"$Env:Appdata"
)
ForEach ($item in $logs_loc) {
Get-ChildItem -Path "$item\*" -Recurse -Force -Include *.log *.log.txt | Remove-Item -Force
}
It takes ~5 seconds and I don't know why. This also doesn't do anything. This code should remove all *.log
or *.log.txt
files under %Appdata%
and %LocalAppdata%
, but it don't delete anything. I tested with test file randomly placed blank *.log
and *.log.txt
but they remain after run.
I haven't tested other part of my script, so there may another problem exists...
TL;DR
- I don't know why my code doesn't work but also takes too much time for running.
- Is there anything that can 'improve' the speed?