My powershell profile (a few time savers)

Recently, I’ve been using powershell on a day-to-day basis for general things, not just writing scripts to perform laborious tasks. I’ve start putting some of those things in to my profile. First is a quick way to edit my profile …

function pro
{
    notepad $profile
}

Simple enough, but save a bit of time 🙂

Now for some more useful stuff

Get all the folders within the current folder which contain Visual Studio solutions …

function Get-Projects
{
    Get-ChildItem -Filter *.sln -Recurse | ForEach-Object { Split-Path -Parent $_.FullName }
}

Okay, so once I’ve moved into one of those folders how do I load the solution in Visual Studio. Well I could do this …

  • *.sln
  • (tab)
  • (enter)

or I could have another powershell function to do that …

function Load-Solution
{
    $sln = (Get-ChildItem -Filter *.sln | Select -First 1).FullName
    Write-Host "Loading $sln ..."
    $shell.ShellExecute("$sln","","","")
}

I also have this in my profile to provide the $shell object

 $shell = New-Object -com shell.application
 

Add a few other things and some aliases in to the mix and this is my profile …

Import-Module ByBoxAppFabric

function pro
{
    notepad $profile
}

function Get-Projects
{
    Get-ChildItem -Filter *.sln -Recurse | ForEach-Object { Split-Path -Parent $_.FullName }
}

function Get-MinutesUntilMidnight
{
    [Math]::Round(([DateTime]::Today.AddDays(1) - [DateTime]::Now).TotalMinutes)
}

function Standup
{
    notepad "C:UsersantonyDocumentsByBox FilesStandup.txt"
}

function HgWorkbench
{
    & "C:Program FilesTortoiseHgthgw.exe"
}

function Load-Solution
{
    $sln = (Get-ChildItem -Filter *.sln | Select -First 1).FullName
    Write-Host "Loading $sln ..."
    $shell.ShellExecute("$sln","","","")
}

$shell = New-Object -com shell.application

Import-Module DistributedCacheAdministration
Use-CacheCluster

New-Alias proj Get-Projects
New-Alias sln Load-Solution
New-Alias hgw HgWorkbench

cd C:DevByBox
  • Adding AppFabric caching modules to allow me to administer my caches without having to load up the AppFabric powershell each time
  • Standup function, to load of my to-do list. It’s called Standup.txt as it just started life as note for my daily standup meeting
  • HgWorkbench function to quickly load of Hg Workbench for the current folder
  • Change directory to my development folder

I have powershell load up on startup, so I can quickly get going without having to wait for all my sidebar gadgets to load up (I have a file launcher gadget too!)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s