Skip to content

Instantly share code, notes, and snippets.

@RichardHan
Last active March 16, 2016 02:58
Show Gist options
  • Save RichardHan/573b56d06c016275d5e0 to your computer and use it in GitHub Desktop.
Save RichardHan/573b56d06c016275d5e0 to your computer and use it in GitHub Desktop.
PowerShell - Count item recurse in folder file
$server_dir = 'C:\somewhere'
if(Test-Path $server_dir)
{
$folders = Get-ChildItem $server_dir | where {$_.PSIsContainer}
$output = @()
foreach($folder in $folders)
{
$fname = $folder.Name
$fpath = $folder.FullName
$fcount = Get-ChildItem -Recurse $fpath | where {!$_.PSIsContainer} | Measure-Object | Select-Object -Expand Count
$obj = New-Object psobject -Property @{FolderName = $fname; FolderPath = $fpath; FileCount = $fcount}
$output += $obj
}
#Output to HTML
$output | ConvertTo-Html -Fragment > 'C:\Temp\Server.html'
}
Start-Process -FilePath "c:\Program Files\Internet Explorer\iexplore.exe" 'C:\Temp\Server.html'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment