Save typing when Manipulating SharePoint Solution Files in PowerShell

 

Introduction

 

One of the things that annoyed me with PowerShell and SharePoint are the following commands:-

  • Add-SPSolution
  • Update-SPSolution
  • Actually anything that requires a –LiteralPath parameter

Don’t get me wrong I think that using PowerShell to admin SharePoint is fantastic but these commands bug me because they require a full path to work correctly. Unfortunately you don’t seem to be able to use the full stop (or period) to represent the current directory.

So you cannot do something like this:-

Add-SPSolution .\mysharepoint.wsp;

Instead you need to do this:-

Add-SPSolution c:\thisisareallylongpath\release1\section2\mysharepoint.wsp

Solution

Anyway, that got me thinking surely there is a better way and I can save myself some typing.

The solution is to use the command Get-Location.

So instead you can do this:-

$curdir = Get-Location;
Add-SPSolution–LiteralPath $curdir”\mysharepoint.wsp”;

Actually there is a PowerShell Alias called gl which is a shortcut for the Get-Location command.

So the shortest version in terms of saving your typing fingers is this:-

$curdir = gl;
Add-SPSolution –LiteralPath $curdir”\mysharepoint.wsp”;

Really hope that helps save you some time, also love to hear any other alternatives, there is bound to be an even better way of doing this.

5 Comments

  1. Hi Simon,

    Nice tip on Get-Location – I hadn’t used that before. Have you tried the Resolve-Path command too? I haven’t re-checked this yet but I think with Resolve-Path you will be able to do something like:

    Add-SPSolution -LiteralPath (Resolve-Path .\mysharepoint.wsp)

    HTH

    Reply

  2. Nice tip!

    I’ve just been using Powershell and Add-SPSolution…I totally agree that having to actually type the literal path seems pointless..

    Great idea!

    Reply

  3. Are you still in Marylebone? I’m running through an install guide you wrote just now – the “BI Deployment guide”

    (Jan release ver 0.8)

    🙂

    Reply

Thoughts? Comments about this post? Please leave them here..

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