Search PowerShellers and other PowerShell-related sites

Wednesday, March 14, 2007

Daily notes with PowerShell

The post at Holistic Detection blog gave me an idea how to keep my daily notes organized and just a few keystrokes away.


function New-DailyNotes {

# store files in subfolder notes in WindowsPowerShell folder
$path = (join-path ([System.IO.FileInfo]$profile).DirectoryName \notes\)
# files will be named like 2007-03-14_notes.txt
$notesfile = (get-date).ToString("yyyy-MM-dd") + "_notes.txt"

if( !(test-path $path ) )
{
# create the notes directory if it doesn't exist
new-item -path $path -type directory
}

$notespath = (join-path $path $notesfile)
if( !(test-path $notespath ) )
{
# create the notes file if it doesn't exist
new-item -path $path -name $notesfile -type "file"
notepad $notespath
}
else
{
notepad $notespath
}

}

set-alias dn New-DailyNotes



I've added this function to the profile file and I only have to type dn to get access to my daily notes file.

No comments: