PowerShell – Always open default SharePoint site ($profile)

Recently I found myself starting each PowerShell window with the same predictable first command (Get-SPSite http://myportalurl).   Knowing that PowerShell supports a start up script ($profile) I thought it may be possible to automate this and save a few seconds each time I need to open a console.   Below is the source code with screenshots.   Hopefully this helps somebody else to save time also.

image

image

image

Add-PSSnapin Microsoft.SharePoint.PowerShell
function Get-DefaultSite() { 
  $site = Get-SPSite http://myportalurl/ 
  $web = $site.OpenWeb(); 
  Return $web; 
}
Return to Top ▲Return to Top ▲