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

  • Home
  • SEARCH
  • 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 775469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:17:40+00:00 2026-05-14T19:17:40+00:00

Let me explain my question. I have a daily report about one PC’s free

  • 0

Let me explain my question. I have a daily report about one PC’s free space as in text file (sp.txt) like:

DateTime       FreeSpace(MB)
-----          -------------
03/01/2010     100.43


DateTime       FreeSpace(MB)
-----          -------------
03/02/2010     98.31

 ....

Then I need to use this file as input to generate a report with difference of free space between dates:

DateTime       FreeSpace(MB)  Change
-----          -------------  ------
03/01/2010     100.43
03/02/2010     98.31           2.12
 ....

Here are some codes I have to get above result without the additional “Change” calculation:

Get-Content "C:\report\sp.txt" `
| where {$_.trim().length -gt 0 -and -not ($_ -like "Date*") -and -not ($_ -like "---*")} `
| Select-Object @{Name='DateTime'; expression={[DateTime]::Parse($_.SubString(0, 10).Trim())}}, `
    @{Name='FreeSpace(MB)'; expression={$_.SubString(12, 12).Trim()}}, `
| Sort-Object DateTime `
| Select-Object DateTime, 'FreeSpace(MB)' |ft -AutoSize # how to add additional column Change to this Select-Object?

My understanding is that Select-Object will return a collection of objects. Here I create this collection from an input text file(parse each line into parts: datetime and freespace(MB)).

In order to calculate the difference between dates, I guess that I need to add additional calculated value to the result of the last Select-Object, or pipe the result to another Select-Object with the calculation as additional property or column. In order to do it, I need to get the previous row’s FreeSpace value. Not sure if it is possible and how?

  • 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-05-14T19:17:41+00:00Added an answer on May 14, 2026 at 7:17 pm

    I think this should work. I just unrolled it into a single loop where we keep track of the last value and use that to create the change property in the select expression. I also changed the parsing code slightly so you are not relying on hard coded substring lengths. It also helped make the select expressions easier to write and understand.

    Get-Content "sp.txt" `
    | where {$_.trim().length -gt 0 -and -not ($_ -like "Date*") -and -not ($_ -like "---*")} `
    | %{ 
        $row = (-split $_ );  
        $obj = select-object -input $row -prop @{Name='DateTime'; expression={[DateTime]($row[0]);};} , `
                            @{Name='FreeSpace(MB)'; expression={[Double]($row[1]);} }, `
                            @{Name='Change'; expression={if($last){$row[1]-$last.'FreeSpace(MB)'}else{0}}}; 
        $last = $obj;
        $obj;
        } | sort DateTime | ft -autosize
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two examples I have a question about. Let me explain via some
I have a question about my functions. Let me explain, I have two functions:
Before asking my question, let me explain the context. CONTEXT: I have a web
Before you all get pissy about me posting this question again, let me explain
with the topic name everyone should be confused let me explain my question.i have
I have a question. It might be sound ridiculous, but let me explain what
Let me explain what I mean with that question: Lets say I have to
Let me explain the situation before I ask the question. I have a site,
I have a question which might be misinterpreted, so let me explain it with
I will explain my question on an example. Let's have following code in C#:

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.