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
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
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
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
| Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Referencing .NET 2.0 but end result uses .NET 3.5 | Israel | .NET General | 5 | 12 Mar 2010 |
| changing the format of date command result | happytoday | PowerShell | 16 | 01 Jan 2010 |
| Parsing email; running a command; and returning the result. | Jason | PowerShell | 1 | 24 Aug 2009 |
| capture command and its output | hugh | PowerShell | 1 | 16 Feb 2008 |
| How can you capture individual thumbnails not full capture ? | Roger | Vista music pictures video | 0 | 05 Nov 2007 |