- #########################
- ##### Configuration
- #########################
- $Target_Directory = "C:\Users\DEDE\Desktop\Test\AllFiles"
- $Deleted_Folder = "C:\Users\DEDE\Desktop\Test\DeletedFiles"
- $Max_Lines = 9
- $Delete = $false
- ###############################
- ###### Check if admin
- ###############################
- $Is_Admin = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544")
- if (-Not ($Is_Admin)) {
- Write-Host 'You have to run this script as Administrator.'
- write-host "Press any key to continue..."
- [void][System.Console]::ReadKey($true)
- Exit
- }
- #########################
- ##### Main
- #########################
- Clear-Host
- Write-Host "=== Start" -BackgroundColor Black
- $Total_Files = 0
- $Deleted_Files = 0
- $Skipped_Files = 0
- Get-ChildItem $Target_Directory -Recurse -Include *.* |
- Foreach-Object {
- $Total_Files++
- $Current_Lines = $Current_Lines.Lines
- # Check if lines are less than
- if ($Current_Lines -lt $Max_Lines) {
- $Deleted_Files++
- if ($Delete) {
- Write-Host "$($_.FullName) has $Current_Lines/$Max_Lines lines: deleting..." -BackgroundColor Red
- } else {
- Write-Host "$($_.FullName) has $Current_Lines/$Max_Lines lines: moving..." -BackgroundColor Blue
- $Temp_Destination = "$Deleted_Folder\$($_.Name)"
- }
- } else {
- Write-Host "$($_.FullName) has $Current_Lines/$Max_Lines lines: skipping..." -BackgroundColor Green
- $Skipped_Files++
- }
- }
- Write-Host "===== Results" -BackgroundColor Black
- If ($Delete) {
- Write-Host "Total Files: $Total_Files | Deleted Files: " -NoNewLine -BackgroundColor Black
- Write-Host "$Deleted_Files" -ForegroundColor Red -NoNewline -BackgroundColor Black
- } else {
- Write-Host "Total Files: $Total_Files | Moved Files: " -NoNewLine -BackgroundColor Black
- Write-Host "$Deleted_Files" -ForegroundColor Blue -NoNewline -BackgroundColor Black
- }
- Write-Host " | Skipped Files: " -NoNewLine -BackgroundColor Black
- Write-Host "$Skipped_Files " -ForegroundColor Green -BackgroundColor Black
Последни пейстове