Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (gci C:Scripts -r | ? {$_.PSIsContainer -eq $True}) | ? {$_.GetFiles().Count -eq 0} | select FullName
- (gci C:Scripts -r | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0} | select FullName
- (gci C:Scripts -r | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0} | select FullName
- Function Get-EmptyDirectories($basedir) {
- Get-ChildItem -Directory $basedir | Where-Object { $_.GetFileSystemInfos().Count -eq 0 }
- }
- $Datefn=Get-Date -format M.d.yyyy_HH.mm.ss
- #Set The File Name for the log file
- $DelFileName = $Datefn
- #Set The File Ext for the log file
- $DelFileExt = " - Old Files" + ".log"
- #Set The File Name With Ext for the log file
- $DelFileName = $DelFileName + $DelFileExt
- #Set Log Path
- $LogPath = [Environment]::GetFolderPath("Desktop")
- $Path = 'Q:'
- $NumDays = 365
- Get-ChildItem -Path $Path -Exclude DCID.txt,*.exe -Recurse | Where-Object {$_.lastwritetime -lt`
- (Get-Date).addDays(-$NumDays) -and $_.psiscontainer -eq $false} |
- ForEach-Object {
- $properties = @{`
- Path = $_.Directory`
- Name = $_.Name
- DateModified = $_.LastWriteTime
- Size = $_.Length / 1GB }
- New-Object PSObject -Property $properties | select Path,Name,DateModified, Size
- } |
- Out-File "$LogPath$DelFileName"
- <#
- #Removes the files found
- Get-ChildItem -Path $Path -Exclude DCID.txt,*.exe -Recurse | Where-Object {$_.lastwritetime -lt`
- (Get-Date).addDays(-365) -and $_.psiscontainer -eq $false} | Remove-Item -Recurse -Force
- #Removes empty folders
- DO {
- $a = (Get-ChildItem $Path -Recurse | Where-Object {$_.PSIsContainer -eq $true}) | Where-Object`
- {$_.GetFileSystemInfos().Count -eq 0} | Select-Object Fullname
- $a
- (Get-ChildItem $Path -Recurse | Where-Object {$_.PSIsContainer -eq $true}) | Where-Object`
- {$_.GetFileSystemInfos().Count -eq 0} | Remove-Item -Force
- }
- WHILE ($a -ne $null)
- #>
- Get-ChildItem C:Scripts -Recurse -Directory | Where-Object {!$_.GetFileSystemInfos().Count}
Add Comment
Please, Sign In to add comment