Posted On March 29, 2019

Find Empty Directories

kimconnect 0 comments
blog.KimConnect.com >> Codes , Windows >> Find Empty Directories
$directories="\\FILESERVER01\SHARE01"

# Dynamic Credential method 1
$who = whoami
	if ($who.substring($who.length-2, 2) -eq "-admin"){$username=$who;}
    else {$username=$who+"-admin";}
#$password = Read-Host -Prompt "Input the password for account $username" -AsSecureString
$password=convertto-securestring "PASSWORD" -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username,$password
$elevate = New-PSSession -ComputerName "JUMPBOX01" -Credential $cred

function listEmptyFolders($items){
    $items | foreach {
        Get-ChildItem $_ -Recurse –ErrorAction SilentlyContinue | Where-Object -FilterScript {$_.PSIsContainer -eq $True} | Where-Object -FilterScript {($_.GetFiles().Count -eq 0) -and $_.GetDirectories().Count -eq 0} | Select-Object -ExpandProperty FullName
        }
}

listEmptyFolders $directories

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

IIS Mime Types

One of the features of IIS security is to enforce file access by its associated…

How to Import Files Into a Docker Container

1. Use SCP to copy files to the remote server while logged onto the local…

PowerShell: Export Event Logs by a Certain Date Range

# User defined variables $daysLimit=7 $startdate=(get-date).adddays(-$daysLimit) $computername=$env:computername $logName='Application' $filterTypes='Error','Warning' $logPath="c:\temp\eventlogs-from-$($startdate.tostring('yyyy-MM-dd'))-to-$((get-date).tostring('yyyy-MM-dd')).csv" # Get the event logs…