Get Oldest File in a Directory

Posted by Drothism on Mar 17th, 2009

Looking for a quick way to get the oldest file in a directory? Here is a quick and dirty method to do it with PowerShell…
dir f:\archive -recurse| ?{!($_.PSIsContainer)} | sort -property lastwritetime | select -first 1
The ?{!($_.PSIsContainer)} filter will leave sub-directories out of the search.


Task Scheduler Syntax

Posted by Drothism on Jan 21st, 2009


Enables an administrator to create, delete, query, change, run, and end scheduled tasks on a local or remote computer. Running Schtasks.exe without arguments displays the status and next run time for each registered task.


PowerShell Special Characters

Posted by Drothism on Dec 12th, 2008

Here are some of the special characters that can be used in Windows PowerShell output:

`0 — Null
`a — Alert
`b — Backspace
`n — New line
`r — Carriage return
`t — Horizontal tab
`’ — Single quote
`” — Double quote

Some of these characters are intended for use only from the Windows PowerShell prompt. For example, the special character `a [...]


Searching a Text File in PowerShell

Posted by Drothism on Sep 18th, 2008

If you are looking for a quick and simple way to search a text file for a certain string PowerShell has a very efficient method called Select-String. In its simplest form just use the following format…
if (select-string -pattern “findme” -path “D:\Scripts\test.txt”)
    Write-Host “Found It!”
In the case above I am searching the text file “text.txt” for the [...]


Creating PowerShell Exit Codes

Posted by Drothism on Sep 10th, 2008

I needed to create a PowerShell script today that would return exit codes. Simply look it up on the internet you say. Well after 30 minutes of searching I did find the trick and thought embedding on here would ensure I could find it next time it was needed…


$host is a PowerShell reserved variable so [...]


Robocopy Exit Codes

Posted by Drothism on Sep 10th, 2008

Every once in a while I go looking for these return codes and end up spending several minutes searching the Internet for them. Of course, this time I ended up finding them in the obvious place - the README for Robocopy. Here they are, for posterity.
The return code from Robocopy is a bit map, defined [...]


Adding timestamps in a DOS batch file

Posted by Drothism on Aug 5th, 2008