Last active
March 16, 2016 02:58
-
-
Save RichardHan/573b56d06c016275d5e0 to your computer and use it in GitHub Desktop.
PowerShell - Count item recurse in folder file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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