Guest User

Untitled

a guest
Jan 23rd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. (gci C:Scripts -r | ? {$_.PSIsContainer -eq $True}) | ? {$_.GetFiles().Count -eq 0} | select FullName
  2.  
  3. (gci C:Scripts -r | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0} | select FullName
  4.  
  5. (gci C:Scripts -r | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0} | select FullName
  6.  
  7. Function Get-EmptyDirectories($basedir) {
  8. Get-ChildItem -Directory $basedir | Where-Object { $_.GetFileSystemInfos().Count -eq 0 }
  9. }
  10.  
  11. $Datefn=Get-Date -format M.d.yyyy_HH.mm.ss
  12. #Set The File Name for the log file
  13. $DelFileName = $Datefn
  14. #Set The File Ext for the log file
  15. $DelFileExt = " - Old Files" + ".log"
  16. #Set The File Name With Ext for the log file
  17. $DelFileName = $DelFileName + $DelFileExt
  18. #Set Log Path
  19. $LogPath = [Environment]::GetFolderPath("Desktop")
  20. $Path = 'Q:'
  21. $NumDays = 365
  22. Get-ChildItem -Path $Path -Exclude DCID.txt,*.exe -Recurse | Where-Object {$_.lastwritetime -lt`
  23. (Get-Date).addDays(-$NumDays) -and $_.psiscontainer -eq $false} |
  24. ForEach-Object {
  25. $properties = @{`
  26. Path = $_.Directory`
  27. Name = $_.Name
  28. DateModified = $_.LastWriteTime
  29. Size = $_.Length / 1GB }
  30. New-Object PSObject -Property $properties | select Path,Name,DateModified, Size
  31. } |
  32. Out-File "$LogPath$DelFileName"
  33. <#
  34. #Removes the files found
  35. Get-ChildItem -Path $Path -Exclude DCID.txt,*.exe -Recurse | Where-Object {$_.lastwritetime -lt`
  36. (Get-Date).addDays(-365) -and $_.psiscontainer -eq $false} | Remove-Item -Recurse -Force
  37. #Removes empty folders
  38. DO {
  39. $a = (Get-ChildItem $Path -Recurse | Where-Object {$_.PSIsContainer -eq $true}) | Where-Object`
  40. {$_.GetFileSystemInfos().Count -eq 0} | Select-Object Fullname
  41. $a
  42. (Get-ChildItem $Path -Recurse | Where-Object {$_.PSIsContainer -eq $true}) | Where-Object`
  43. {$_.GetFileSystemInfos().Count -eq 0} | Remove-Item -Force
  44. }
  45. WHILE ($a -ne $null)
  46. #>
  47.  
  48. Get-ChildItem C:Scripts -Recurse -Directory | Where-Object {!$_.GetFileSystemInfos().Count}
Add Comment
Please, Sign In to add comment