SOLVED

Trying to create a table via Powershell

Copper Contributor

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\...
RootFolder\DDDD0001\Apps\...
goes on

 

I wanna get an output something like this

Ref                  AppFolderSize(GB)
AAAA0001     3GB
BBBB0001      2GB
CCCC0001      5GB
DDDD0001    8GB
etc. 

 

Has someone done this? 

3 Replies

@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

Thanks @Erick A. Moreno R. 

I'll give it a go :) 

best response confirmed by MichaelNazli (Copper Contributor)
Solution

 

 

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

1 best response

Accepted Solutions
best response confirmed by MichaelNazli (Copper Contributor)
Solution

 

 

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

View solution in original post