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

PowerShell: Convert CSV Into HashTable

This is an illustration of a function to convert a set of CSV contents into…

PowerShell: Check TCP Connections of Server by Port Numbers

# Check-TCP-Connections.ps1# This function will output progress onto the console as well as returning a…

Basic CSS: Add Rounded Corners with border-radius

<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css"><style>.red-text {color: red;}h2 {font-family: Lobster, monospace;}p {font-size: 16px;font-family: monospace;}.thick-green-border {border-color: green;border-width: 10px;border-style:…