Announcing “Save PowerShell To SharePoint” CodePlex Project

logo-home[1]

In this post I will talk about a new script I wrote to save PowerShell ISE files to a versioned SharePoint document library as well as a side project I created on CodePlex to host this code and future releases.

Background

Recently I began listening to the PowerScripting Podcast and I’m slowly catching up on old podcasts.  On episodes 121 and 122 (most recent ones I’ve listened to as of this writing) Hal and Jonathan talked about an idea that piqued my interest immediately: using SharePoint as a script repository for PowerShell scripts.  As I was in my car at the time I began to brainstorm ideas on how to accomplish this and what should be in scope for such a project.  As soon as I reached my destination I began working on a proof of concept and subsequent list of additional tasks to flesh this out.  Below you will find an adaptation of my C# code snippet to upload a file to a SharePoint document library (blogged about here) that I worked into a PowerShell script.

Add-Type -TypeDefinition @"

using System.Net;

using System.Text;


public class SharePointFileUploader

{

    public static void UploadFile(string textToOutput, string uploadPath)

    {

        ASCIIEncoding encoder = new ASCIIEncoding();

        byte[] bytesToOutput = encoder.GetBytes(textToOutput.ToString());

        using (WebClient client = new WebClient())

        {

            client.Credentials = System.Net.CredentialCache.DefaultCredentials;

            client.UploadData(uploadPath, "PUT", bytesToOutput);

        }


        return;

    }

}

"@


$documentLibraryPath = Read-Host -Prompt "Enter URL of Document Library";

$documentLibraryPath = $documentLibraryPath.TrimEnd('/')


foreach($aFile in $psise.CurrentPowerShellTab.Files)

{

    $textToOutput = $aFile.Editor.Text;

    $uploadPath = "$documentLibraryPath/$($aFile.DisplayName.Replace('*', ''))";


    [SharePointFileUploader]::UploadFile($textToOutput, $uploadPath)

}

What The Script Does

Note: This script is just a proof of concept that took 15 minutes to write and is not entirely fleshed out.  With that said, this script declares a new type that uploads a string to a specified URL path.  Next it loops through all open files in your PowerShell ISE and uploads the content of these files (even unnamed/unsaved files) to a SharePoint document library using our newly added type.  The beauty is that if you have turned on versioning for your document library the file content will add a new version.

Future Goals

While it is nice to have a script that performs this upload manually, wouldn’t it be nice to have this functionality happen automatically similar to how Microsoft Office Word or Excel auto saves your work every X minutes.  That idea has led me to draw up some additional features I would like to build in as my spare time allows.  Here are a few of those planned features (some already under development or research begun):

  • Create/select SharePoint document library through a form (WPF?)
  • Create background job to automatically run upload process every X minutes while PowerShell host is open
  • Add support for PowerShell console (history commands?)
  • Add support for deploying as a module with configuration settings in profile
  • Add support for SharePoint 2010 native PowerShell commandlets
  • Retrieve past version of script from document library
  • Create help file

After I started writing down these features I began to realize that perhaps there would be enough interest to make this script into a CodePlex project that could be community developed and reviewed.

CodePlex Project

I am happy to announce the creation of Save PowerShell To SharePoint as a new CodePlex project.  I have to admit, I have never created or participated in a CodePlex project up to this point.  Despite my lack of previous involvement I feel like this is a great pet project for me to break into a community project.  This project is currently in the alpha stages while I upload the script code and work on documenting the current status and to-do items.  I’m trying to work towards attainable goals and plan on this being an organic project rather than planning on version X.0 from the get go.

Conclusion

In this post I provided a proof of concept PowerShell script for uploading the currently opened files in a PowerShell ISE instance and also announced the creation of my first CodePlex project Save PowerShell To SharePoint.  Overall I am very excited to begin work on this project as it combines two of my great passions: PowerShell and SharePoint.  A big thank you to Hal and Jonathan for bringing up this idea as I don’t want to steal any of their credit for the formation of the idea.  Once again it amazed me that PowerShell provided a lightweight platform to throw together a useful script in such a short amount of time.  I know that I won’t be able to devote as much time to this as I would like at first, but great things start with baby steps.  Please feel free to try out the script and leave feedback on the project site as development progresses.

-Frog Out

Links

PowerScripting Podcast home page

PowerScripting Podcast Episode 122 – Don Jones Scripting Editor Shoot-Out

PowerScripting Podcast Episode 121 – Jay Dave on UAC and AppLocker

Programmatically uploading files to a SharePoint 2007 document library

Save PowerShell To SharePoint CodePlex project page

Guest Blog Post On “Hey, Scripting Guy!” Published

ee516741_HEY_SCRIPTING_GUY_left

A few days ago I mentioned that I had been busy recently writing a guest blog post for a fairly high profile blog.  Today I can happily announce the details.  My article “Deploy a PowerShell Module with SharePoint Cmdlets” was published on the Hey, Scripting Guy! blog this morning.  Click here for the link.

Anyone familiar with Windows PowerShell will most likely know the Scripting Guy Ed Wilson and his teammate Craig Liebendorfer.  A little over a month ago Ed asked if I would submit a guest blog post and I eagerly agreed.  Please check it out and leave some feedback if you have any.

 

-Frog Out

 

Links

Deploy a PowerShell Module with SharePoint Cmdlets

http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/29/deploy-a-powershell-module-with-sharepoint-cmdlets.aspx?utm_source=twitterfeed&utm_medium=twitter

Adding Intellisense for SharePoint 2010 Custom Workflow .Actions File

    This post will show you how to add inteliisense support for custom workflow .actions files in SharePoint 2010.  During the course of some research for my writing I found out that the SharePoint 2010 SDK doesn’t include intellisense for the .actions files (at least as of the August 2010 release).  As the schema can be a bit difficult to remember off I searched the interwebs to see if anyone had implemented this already.  As luck would have it I was able to find this blog post that included an XSD file, but no instructions on how to install it.  That’s where I’ll help you fill in the gaps.

Steps

  1. Download schema file
  2. Rename schema file from .xml to .xsd
  3. Copy schema file to Visual Studio directory
  4. Update SharePoint catalog files

    First thing to do is download the wssactions.xml file from this location and rename it to wssactions.xsd.  Copy the file to your Visual Studio 2010 XML templates folder which is typically something like “C:Program Files (x86)Microsoft Visual Studio 10.0XMLSchemas”.  Next open the SharePoint catalog files (WssSchemaCatalog64.xml and WssSchemaCatalog.xml) and insert the below child element into the SchemaCatalog element for both.

<Association extension=”actions” schema=”%InstallRoot%/xml/schemas/wssactions.xsd” />

    Once you have completed this you’re all set to go.  No need to even re-launch Visual Studio 2010.  Create a new .xml file named <some_name>.actions.  You should be able to begin receiving intellisense for your workflow action definition file.

Conclusion

    In just a few short minutes you too can have intellisense for your SharePoint 2010 custom .actions files.  Special thanks to the author of the blog with the schema file download (I wasn’t able to find out the author’s name).  Also thanks to Dave Kehring for a template for what and where to add to the catalog files.  Hopefully this will help you get up and running SharePoint 2010 custom actions quicker and more effectively.  Enjoy!

 

      -Frog Out

Co-Authoring a Book and Guest Blog Post Coming Soon

    A few posts ago you may have read that I have a few side projects going on that would be taking up my time the next few months.  I can’t give you full details on many of those yet, but I did want to drop a little information as I’ve been getting questions from friends lately.

    The first thing that I’m working on is a writing two chapters for a book coming from a big (at least in the SharePoint world) publisher.  This project came about because of some great connections I’ve made in the SharePoint community through conferences, speaking engagements, user groups, etc.  I don’t have a firm publish date, but I can tell you that this book is exclusively SharePoint 2010 and I’m working with some amazing authors on it.  This is my first crack and writing for a book and it’s been quite a ride so far, especially draining much of that elusive “free time” I thought I would have after SPSColumbus finished.  More details on this later.

    The second thing I was working on (just finished a week ago) is a guest blog post for a fairly big name blog.  I was a bit surprised when the blog owner asked me to write a guest post, but I am honored to submit a post to them.  The subject matter is a really fun idea I had recently that a few people on Twitter recommended I blog about.  Looks like I will get the chance to, just on a much larger distribution than my own blog.  I do know the date that will be published, but I’ll write another post announcing when it actually happens in case dates get shifted for any reason.  You won’t have to wait long for that one though.

    Aside from those 2 big items there are a few other items a little further out that I’m working on.  I have confirmed two new SharePoint 2010 presentations that I’ll be giving for the first time at different conferences in the coming months.  One is on connecting SharePoint 2010 to Line of Business (LOB) applications and the other on the new SharePoint 2010 developer tools.  I’m excited to be creating new presentation materials in these areas.

Conclusion

    Hopefully I’ve answered some questions that I’ve been getting recently or at least given you some insight into what I’m working on currently.  Sorry I can’t give more details but they will come in due time.  Until then happy SharePoint-ing and keep sharing and growing the community.

 

      -Frog Out

4 Reasons Why You Should Use SYSPREP

    If you build virtual machines running Windows operating systems and aren’t using SYSPREP you are costing yourself untold amounts of time.  This post will explain be a brief explanation as to why.

Background

    Over the past few weeks I’ve been rebuilding about a dozen of my virtual machines (VMs) due to getting a new work laptop and finally having the hardware to run 3+ of them at once.  The last time I went through a rebuild of VMs like this I started to dig into using SYSPREP so reduce the amount of time.  For those unfamiliar, SYSPREP is a Microsoft utility that allows you to create a single base VM using the operating system (OS) of your choice and then clone that VM as much as you want.  By itself that may not sound like much but in addition to cloning the OS you also carry over any of the system updates applied, applications installed, and most other configurations you perform.  This will be a very important point to keep in mind.

Why Use SYSPREP

  1. Windows Updates – If you’ve ever installed a fresh Windows operating system and then gone into Windows Update you’re probably familiar with being greeted by a double digit (sometimes even triple digit) list of updates to apply.  SYSPREP allows you to install those updates just once on the base image and then all cloned VMs will already have them installed.  In my situations dozens of hours of Windows Updates are reduced to just an hour or two.
  2. Reduce install time of OS and applications – To a certain degree there is no install time.  When you SYSPREP a machine you can choose an option to generalize the install.  This means stripping out the SID and other personalization, so that when it reboots you can treat it like an entirely new machine with only minor configurations needed to get started.  Applications that you install on the base image are also carried over to cloned VMs.  There’s nothing like trying to sort out and remember all of the various 3rd party installs that you put onto your VMs.
  3. Quickly expand server farm – Most of the applications I work with (SharePoint specifically) are deployed to a server farm.  With my new hardware I am able to run multiple web front end servers (WFEs), additional “client” machines, and other configurations that were previously not possible.  If I want to spin up a fresh WFE I can clone the base image, join it to the farm, and be rolling in 30 minutes instead of hours it would take to create a fresh VM.
  4. Consistency – Consistency may not sound like a big deal, but when you are dealing with complex applications like SharePoint one less variable can mean far fewer headaches.  When you know that all of your VMs come from a base starting point that reduces overall variance.

Conclusion

    All said and done I can honestly say I’ve saved myself days (literally) of effort by using SYSPREP.  I keep a copy of Windows 7, Server ‘03 R2, Server ‘08, and Server ‘08 R2 in the before, during, and after stages of SYSPREP.  The before stage is important so that in a few months when more updates are released I can just apply them to that image and create a new base image to use instead of starting all over from scratch.  Hopefully after reading this post I’ve convinced you to at least look into SYSPREP if you’re not using it already.

 

      -Frog Out

Slides and Scripts from BuckeyeSPUG August 2010 Presentation

    This month I had the pleasure of presenting at the BuckeyeSPUG (formerly Central Ohio SPUG) meeting here in Columbus, OH.  This is the first time I was the main presenter at our user group, having done small presentations along with other presenters in past meetings.  The attendees had some great questions and hopefully learned some new tricks to use on their SharePoint 2007 farms.  Thanks to everyone who came out.  Below are the slides and demo scripts for those interested.

 

Slides and Scripts: click here