<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Find Empty Folders Using Powershell Archives - the Sysadmin Channel</title>
	<atom:link href="https://thesysadminchannel.com/tag/find-empty-folders-using-powershell/feed/" rel="self" type="application/rss+xml" />
	<link>https://thesysadminchannel.com/tag/find-empty-folders-using-powershell/</link>
	<description>Documenting My Life as a System Administrator</description>
	<lastBuildDate>Mon, 11 Oct 2021 01:57:45 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>
<site xmlns="com-wordpress:feed-additions:1">144174110</site>	<item>
		<title>How To Find Empty Folders Using Powershell</title>
		<link>https://thesysadminchannel.com/find-empty-folders-powershell/</link>
					<comments>https://thesysadminchannel.com/find-empty-folders-powershell/#comments</comments>
		
		<dc:creator><![CDATA[Paul Contreras]]></dc:creator>
		<pubDate>Mon, 11 Oct 2021 01:57:45 +0000</pubDate>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Find Empty Folders Using Powershell]]></category>
		<guid isPermaLink="false">https://thesysadminchannel.com/?p=678</guid>

					<description><![CDATA[<p>Anytime you&#8217;re doing cleanup on a share or a local directory, it&#8217;s always a good idea to prep and find empty folders using Powershell. A good use case is if you&#8217;re going to permanently archive a folder, and you want&#8230; <a href="https://thesysadminchannel.com/find-empty-folders-powershell/" class="more-link">Continue Reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a href="https://thesysadminchannel.com/find-empty-folders-powershell/">How To Find Empty Folders Using Powershell</a> appeared first on <a href="https://thesysadminchannel.com">the Sysadmin Channel</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Anytime you&#8217;re doing cleanup on a share or a local directory, it&#8217;s always a good idea to prep and find empty folders using Powershell.  A good use case is if you&#8217;re going to permanently archive a folder, and you want to do some cleanup to remove the excess baggage of folders that no longer have anything inside them, this would be an excellent tool to make that happen.</p>
<p>This Powershell script uses <strong>Get-ChildItem</strong> under the hood and also supports the <strong>Depth</strong>, <strong>Recurse</strong> and <strong>Path</strong> Parameters to give you a bit more flexibility on your queries.  It also allows you to use UNC paths as well so you can easily use this for network drives if that&#8217;s what you choose to audit.</p>
<h2>How To Find Empty Folders Using Powershell</h2>
<p>Let&#8217;s move on to the script on how to find empty folders using Powershell.</p>
<pre class="brush: powershell; title: ; notranslate">

Function Get-EmptyDirectory {
&lt;#
.SYNOPSIS
    Get empty directories using underlying Get-ChildItem cmdlet

.NOTES
    Name: Get-EmptyDirectory
    Author: theSysadminChannel
    Version: 1.0
    DateCreated: 2021-Oct-2
 
.LINK
     https://thesysadminchannel.com/find-empty-folders-powershell/ -
 
.EXAMPLE
    Get-EmptyDirectory -Path \\Server\Share\Folder -Depth 2 
#&gt;

    [CmdletBinding()]

    param(
        [Parameter(
            Mandatory = $true,
            Position = 0
        )]
        [string]    $Path,

        [Parameter(
            Mandatory = $false,
            Position = 1
        )]
        [switch]    $Recurse,

        [Parameter(
            Mandatory = $false,
            Position = 2
        )]
        [ValidateRange(1,15)]
        [int]    $Depth
    )

    BEGIN {}

    PROCESS {
        try {
            $ItemParams = @{
                Path      = $Path
                Directory = $true
            }
            if ($PSBoundParameters.ContainsKey('Recurse')) {
                $ItemParams.Add('Recurse',$true)
            }

            if ($PSBoundParameters.ContainsKey('Depth')) {
                $ItemParams.Add('Depth',$Depth)
            }
            $FolderList = Get-ChildItem @ItemParams | select -ExpandProperty FullName

            foreach ($Folder in $FolderList) {
                if (-not (Get-ChildItem -Path $Folder)) {
                    [PSCustomObject]@{
                        EmtpyDirectory = $true
                        Path           = $Folder
                    }
                } else {
                    [PSCustomObject]@{
                        EmtpyDirectory = $false
                        Path           = $Folder
                    }
                }
            }
        } catch {
            Write-Error $_.Exception.Message
        }
    }

    END {}
}

</pre>
<div id="attachment_3490" style="width: 922px" class="wp-caption aligncenter"><a href="https://thesysadminchannel.com/wp-content/uploads/2021/10/Get-Empty-Directory-Powershell-Script.png" target="_blank" rel="noopener"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-3490" src="https://thesysadminchannel.com/wp-content/uploads/2021/10/Get-Empty-Directory-Powershell-Script.png" alt="Get Empty Directory Powershell Script" width="912" height="543" class="size-full wp-image-3490" srcset="https://thesysadminchannel.com/wp-content/uploads/2021/10/Get-Empty-Directory-Powershell-Script.png?v=1633916355 912w, https://thesysadminchannel.com/wp-content/uploads/2021/10/Get-Empty-Directory-Powershell-Script-125x75.png?v=1633916355 125w, https://thesysadminchannel.com/wp-content/uploads/2021/10/Get-Empty-Directory-Powershell-Script-768x457.png?v=1633916355 768w" sizes="(max-width: 912px) 100vw, 912px" /></a><p id="caption-attachment-3490" class="wp-caption-text">The Script is showing EmptyFolder as True.  Windows Explorer also confirms this.</p></div>
<h2>Conclusion</h2>
<p>If you&#8217;re looking for a quick and easy way to find empty folders using Powershell, this script will definitely do the job and do it well. The great thing about it is that it is extremely portable so you can copy and paste this script onto another machine and run it locally if you prefer not to have it ran remotely.</p>
<p>For more content like this, be sure to check out our <a href="https://thesysadminchannel.com/powershell/" rel="noopener" target="_blank">real world Powershell scripts</a> just like this to make sure your sysadmin journey a little easier.</p>
<p>The post <a href="https://thesysadminchannel.com/find-empty-folders-powershell/">How To Find Empty Folders Using Powershell</a> appeared first on <a href="https://thesysadminchannel.com">the Sysadmin Channel</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://thesysadminchannel.com/find-empty-folders-powershell/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">678</post-id>	</item>
	</channel>
</rss>
