Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8751661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:05:30+00:00 2026-06-13T13:05:30+00:00

I’m new to the Powershell and would need some help with a problem. I

  • 0

I’m new to the Powershell and would need some help with a problem. I created a function which returns an object with Infos about the Directory:

DATE: 10-12-2012

COMPUTER: PC1

DIRECTORY: C:\TEMP

FOLDERSIZE_IN_MB: 70

I loop through the directories to collect information of their sizes and export it to a CSV file once a week.

HERE STARTS MY PROBLEM:

I want to get some information about the dir growth. I started to write a script with import the oldest and newest CSV files.

$data="C:\LOG\Data"
$data= gci -path $data -filter "*.csv" 
$temp=""
$old,$new=@()

foreach($item in $data){


    If((Get-Date $item.LastWriteTime -format ("ddMMyyyy")) -gt $temp){

       $new+= $item.FullName |Import-CSV -delimiter ";"
    }
    Elseif((Get-Date $item.LastWriteTime -format ("ddMMyyyy")) -lt $temp){
        $old+= $item.FullName |Import-CSV -delimiter ";"
    }

 $temp=(Get-Date $item.LastWriteTime -format ("ddMMyyyy"))
}

How can I compare the two arrays to find equal dir vlaues in both and callculate with thier sizes?

I dont know how to check:

IF C:\TEMP in OLD and C:\TEMP in NEW then callulate (1-(SIZEOLD/SITZENEW))*100.

I would be nice to get an output like:

DATE: 10-12-2012

COMPUTER: PC1

DIRECTORY: C:\TEMP

FOLDERSIZE_IN_MB: 80,5

GROWTH_SINCE_LAST_SCAN: 15%

This is what I did to resolve my problem but I does not look solid and I do not know how to convert the hash back into an object to pipe the result into a csv.

$old=$old|Group-object Item
$new=$new|Group-object Item

$result1=compare $new $old -property Name -includeequal -passthru |WHERE {$_.Sideindicator -eq "=="}
$result2=compare $old $new -property Name -includeequal -passthru |WHERE {$_.Sideindicator -eq "=="}

for($i=0;$i -le $result1.count;$i++){

    if($result1[$i].Name -contains $result2[$i].Name){

      $Size2=($result2[$i].Group)| select-object -property FolderSize_in_MB
      $Size1=($result1[$i].Group)| select-object -property FolderSize_in_MB    

          if(([int]$Size1.FolderSize_in_MB) -ne "0"){
              $growth=(1-(([int]$Size2.FolderSize_in_MB)/([int]$Size1.FolderSize_in_MB)))*100
          }
          else{
                $growth="0"
          }
       }
    else{

    }
    if($result1[$i]){

   $result1[$i].Group| ADD-Member NoteProperty Growth ("{0:n2}"-f $growth +"%")


   } 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:05:31+00:00Added an answer on June 13, 2026 at 1:05 pm

    The most forward way would be based on gci | measure-object -sum length. The Scripting Guys have just done it that way.

    For homemade solution, I’d rather store directory names and sizes in a file. On next run, import the data and create a hashtable on its contents. Use full name of each dir as hash key and size as value. Read the current dir sizes and look old sizes from the hashtable. (You could serialize the hashtable, I propably would do that.)

    $ht = @{}
    $oldDirs = import-csv "lastStatus.log" # Assume: Name,Size
    
    $oldDirs | % {
      $ht.Add($_.Name, $_.Size)
    }
    
    $newDirs = gci -path $data -filter "*.csv"
    
    $newDirs | % {
      # If the hashtable contains dir with same name, read the size and print comparison
      if($ht.ContainsKey($_.FullName)) {
        $oldValue = $ht.Item($_.FullName)
        $("{0}, {1}% " -f $_,   (1-($oldValue/$_.Size))*100 ) # Get current size here somehow
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I need a function that will clean a strings' special characters. I do NOT
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.