Capture command result


  1.    19 Dec 2006 #1
    Bruce Wilkinson Guest

    Capture command result


    How do a capture the result of a command in a script? For example, the
    following will return the file last written, dir | sort -prop LastWriteTime |
    select -last 1. How do I save that so I can later use the name?

    Bruce
      My System SpecsSystem Spec

  2.    19 Dec 2006 #2
    RichS Guest

    RE: Capture command result


    Could try something like this

    PS> $t = dir | sort -prop LastWriteTime | select -last 1
    PS> $t.name
    test1
    PS>


    --
    Richard Siddaway

    Please note that all scripts are supplied "as is" and with no warranty


    "Bruce Wilkinson" wrote:

    > How do a capture the result of a command in a script? For example, the
    > following will return the file last written, dir | sort -prop LastWriteTime |
    > select -last 1. How do I save that so I can later use the name?
    >
    > Bruce

      My System SpecsSystem Spec

  3.    20 Dec 2006 #3
    Andrew Watt [MVP] Guest

    Re: Capture command result


    On Tue, 19 Dec 2006 08:30:00 -0800, Bruce Wilkinson
    <BruceWilkinson@discussions.microsoft.com> wrote:

    >How do a capture the result of a command in a script? For example, the
    >following will return the file last written, dir | sort -prop LastWriteTime |
    >select -last 1. How do I save that so I can later use the name?
    >
    >Bruce


    Bruce,

    I assume you want to save the information in a file. If not then
    simply assign it to a variable as in the first line of code which
    follows.

    The following works for me.

    $a = dir | sort -prop LastWriteTime | select-object -Last 1
    $a > C:\Last.txt

    NOTE: The following does NOT work. At least it doesn't work as
    expected for me.

    (dir | sort -prop LastWriteTime | select-object -Last 1) > C:\Last.txt

    Andrew Watt MVP
      My System SpecsSystem Spec

Capture command result

Similar Threads
Thread Forum
Referencing .NET 2.0 but end result uses .NET 3.5
I'm using DevStudio 2005 and I have a project that references System.dll ver 2.0.50727 and I accidentally compiled code that used an overload that...
.NET General
changing the format of date command result
I need to fix a problem with batch files that it has the command "echo %date%" inside them . So , I run them in a lot of machines and every machine...
PowerShell
Parsing email; running a command; and returning the result.
Hi guys. I've been out of the Powershell scene for a while because I got a new job outside of IT, but I've wanted to do something that would help...
PowerShell
strange result when adding $
Hello everyone, 1. $a=0 $x=($a++) then $x is 0. but
PowerShell
capture command and its output
Hi all I am in the process of learning PS so I am trying the different cmdlets to see wht they do what the output is etc. I would like to log...
PowerShell
How can you capture individual thumbnails not full capture ?
I am capturing my video from my Sony HDR-HC5 in HD into windows movie maker fine, but it captures as 1 thumbnail in dvr-ms format ie full lenght of...
Vista music pictures video
Search Result
How to view search result in normal (without underline)..................when i type any filename in start icon---->start search......... the...
Vista General

Our Sites
  • Ten Forums
  • Eight Forums
  • Seven Forums
  • Help Me Bake
  • Site Links
  • Contact Us
  • Privacy and Cookies
  • About Us
    Windows Vista Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

    Designer Media Ltd
    All times are GMT -5. The time now is 13:19.
    .