Well, to not arbitrarily delete root / OS/boot drive stuff, I'd consider a small change.
$Folder = Read-Host -Prompt 'Enter the full path to the target folder tree to delete'
If ($Folder -match 'C:')
{
Write-Warning -Message "You are making a distructive action on the $Folder. Are you sure you want to do this?"
<#
#Delete files older than 6 months
Get-ChildItem $Folder -Recurse -Force -ea 0 |
? {!$_.PsIsContainer -and $_.LastWriteTime -lt (Get-Date).AddDays(-180)} |
ForEach-Object {
$_ | del -Force
$_.FullName | Out-File C:\log\deletedlog.txt -Append
}
#>
}
Else
{
"Working on deleting the folder tree $Folder"
<#
#Delete empty folders and subfolders
Get-ChildItem $Folder -Recurse -Force -ea 0 |
? {$_.PsIsContainer -eq $True} |
? {$_.getfiles().count -eq 0} |
ForEach-Object {
$_ | del -Force
$_.FullName | Out-File C:\log\deletedlog.txt -Append
}
#>
}