Forum Discussion
MichaelNazli
May 30, 2020Copper Contributor
Trying to create a table via Powershell
Hi Guys, I do have bunch of target folders that I'm trying to check them regularly via PS script; RootFolder\AAAA0001\Apps\... RootFolder\BBBB0001\Apps\... RootFolder\CCC00001\Apps\... RootFol...
- Jun 28, 2020
dir c:\RootFolder -dir | ft name,@{Label=”AppFolderSize(GB)”;Expression= {“{0:n2} GB” -f ((dir -rec $_|measure length -sum -ErrorAction SilentlyContinue).sum /1gb)}}
MichaelNazli the script above is a single line of code and the output will be something like this:
Name AppFolderSize(GB) ---- ----------------- kkk 0,00 GB m 2,54 GB office2019-last 1,88 GB symbols 0,00 GB up2 0,00 GB uplanner 0,00 GB
bye Gas
Erick A. Moreno R.
Jun 02, 2020Iron Contributor
MichaelNazli I think this should help you.
$FoldersInRootFolder = Get-ChildItem -Path '\RootFolder\AAAA0001' -Directory -ErrorAction SilentlyContinue
$Results = @()
ForEach($Folder in $FoldersInRootFolder)
{
$Childs = Get-ChildItem -Path $Folder.FullName -Recurse -Force -ErrorAction SilentlyContinue
$Sum = 0
ForEach($Child in $Childs)
{
$Sum = $Child.Length + $Sum
}
$SumMB = $Sum / 1GB
$Props = [ordered]@{
Ref = $Folder.Name
"AppFolderSize(GB)" = $([math]::Round($SumMB,2))
}
$Results += New-Object PSObject -Property $Props
}
$Results
Regards
Erick Moreno
- MichaelNazliJun 05, 2020Copper Contributor
Thanks Erick A. Moreno R.
I'll give it a go 🙂