Geeks With Blogs
Jamie Kurtz Promoting architectural simplicty

As I get more and more proficient with Windows PowerShell, I find that my profile is getting more and more useful. I thought I’d post my current profile’s content here, in case anyone finds any of these functions useful.

 

set-alias gh get-help

set-alias gcmd get-command

set-alias wo where-object

set-alias ss select-string

function sync {tfpt online /adds /deletes /diff "$args" /recursive /noprompt}

function kil {kill -name $args[0]}

function e {explorer $args[0]}

function sn { & 'C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\sn.exe' $args }

function sn64 { & 'C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\x64\sn.exe' $args }

function prompt { "PS>" }

function hosts { notepad c:\windows\system32\drivers\etc\hosts }

function pro { notepad C:\Users\jkurtz\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 }

function gcp {get-content $args[0] | out-host -paging}

function edit { notepad $args[0] }

function npp { & 'C:\Program Files (x86)\Notepad++\notepad++.exe' $args }

function Replace-String($find, $replace, $path, $include)
{
    ls $path -include $include –exclude *.dll,*.exe -recurse | select-string $find -list | % { echo "Processing contents of $($_.Path)"; (get-content $_.Path) | % { $_ -replace $find, $replace } | set-content $_.Path -Force }
    ls $path *$find* -include $include -recurse |% { echo "Renaming $($_.FullName) to $($_.FullName.Replace($find, $replace))";mv $_.FullName $_.FullName.Replace($find, $replace) }
}


I also tend to keep a running list of change-directory functions handy. For example, if I am working on a project called “Popcorn”, I will create a function that lets me change the current directory to that project’s trunk – like this:

function cd-pc {cd c:\projects\popcorn\trunk; gl }

 

I realize I could use PowerShell drives. But I’m just not all that comfortable using drive letters – mapped drives in Windows or PowerShell drives.

Posted on Monday, July 25, 2011 10:01 PM | Back to top


Comments on this post: My PowerShell Profile

# re: My PowerShell Profile
Requesting Gravatar...
One thing you might consider is creating separate script files for your aliases and functions. In your profile all you need then is to dot source them. This way you can leave your profile alone and simply update the appropriate file.

#dot source alases and functions
. c:\scripts\myaliases.ps1
. c:\scripts\myfunctions.ps1
#profile specific commands
Set-Location C:\Scripts
Left by Jeffery Hicks on Aug 01, 2011 6:06 AM

Your comment:
 (will show your gravatar)


Copyright © Jamie Kurtz | Powered by: GeeksWithBlogs.net