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

How To Automate Youtube Full Screen on Ubuntu Using Python & Selenium

#sudo apt install python3 python3-pip #sudo pip3 install selenium #pip install webdriver-manager # Variables YoutubeUrl="https://www.youtube.com/watch?v=7nT5YawZt-s"…

PowerShell: Enabling and Disabling Network Level Authentication (NLA)

NLA is Microsoft's answer to mitigate some DDoS attacks via remote desktop (RDP). It uses…

Microsoft IIS: How to Forward from HTTP to HTTPS

1. Apply the URL Rewrite module as required:- https://www.iis.net/downloads/microsoft/url-rewrite- Extract and install it 2. Run…