I’m trying to write a script to count subfolders and tell me the number of files and the size of a folder but keep getting “Microsoft.PowerShell.Commands.GenericMeasureInfo” for the file size. Code follows.
function filecount { param ( [string]$path ) if (-not (Test-Path $path)){Throw "Path: $path not found"} $count = 0 $count = Get-ChildItem -Path $path | where {!$_.PSIsContainer} | Measure-Object | select -ExpandProperty count $colItems = 0 $colItems = Get-ChildItem -Path $path | where {!$_.PSIsContainer} | Measure-Object -property length -sum "{0:N2}" -f ($colItems.sum / 1MB) + " MB" Get-Item -Path $path | select PSDrive, @{N="Parent"; E={($_.PSParentPath -split "FileSystem::")[1]}}, Name, @{N="FileCount"; E={$count}}, @{N="FileSize"; E={$colItems}} Get-ChildItem -Path $path | where {$_.PSIsContainer} | foreach { filecount $($_.Fullname) } } filecount "C:temp"
What am I missing? Thanks
submitted by /u/kenfury
[link] [comments]
The post Issue with passing variable resulting in “Microsoft.PowerShell.Commands.GenericMeasureInfo” appeared first on How to Code .NET.