Browsed by
Tag: Community

How to: Automatically log your PowerShell session every time

How to: Automatically log your PowerShell session every time

Preface

At SharePoint Saturday New Hampshire I sat in a packed room and listened as Todd Klindt showed everyone how to install SharePoint 2013 without screwing it up (too badly). The big take away for me was this command that I had not heard about before called start-transcript. The power of start-transcript is that it is able to write everything that you do in a PowerShell session to a log file that you can review later. Todd demo’ed how he throws this every time he opens PowerShell and has found it to be invaluable.

The main reason that I had not heard of start-transcipt before is that I live in PowerShell ISE and rarely (if ever) go into plain ol’ PowerShell, and sadly start-transcript is not supported in PowerShell ISE. DAMN YOU POWERSHELL GODS FOR TEASING ME SO!!!!

The Use Case

The problem that this solves in my view is:

  1. I spend a ton of time tweaking away at some code on a SharePoint server, get it right and then inadvertently close the PowerShell window. It’s just GONE.
  2. Opening and closing PowerShell windows and trying to remember what I manually typed 2 hours ago to fix a problem that got reintroduced after redeploying code.
  3. Needing a way to review who made changes to the serverenvironment and see what they actually did.

The more I thought about it the more the more I liked the ability to log everything that is done in PowerShell on a server, but the issue that I had was that it was something that the person opening PowerShell had to remember to do every time they opened a window.

I started thinking about using PowerShell profiles to implement this for every user. In my experience I have seen profiles used infrequently, but in a couple of the scenarios they have been deployed via AD Group Policy. However if you are working in an environment that you don’t have access to create GPOs or you are working in a development environment and developing GPOs just isn’t your thing what do you do?

The Problem

The task at hand was two-fold:

  1. Auto deploy a PowerShell Profile for SharePoint Admins that would be lightweight, contain the start-transcript function to start automatically, assist in auditing, and be Server Administrator deployable
  2. Figure out if start-transcript like functionality was available for the native PowerShell ISE

The Solution

The solution that I came up with was to leverage the All Users Startup option in Windows to launch a script that would check to see if the folder that holds the PowerShell profile scripts exists. If it exists, the script terminates and all is well. This happens on every interactive login, but takes only a second. If the folder does not exist, the will kick off a creation of the scripts based upon a preset profile definition that includes the targeting & naming of the logs, starting the transcript, and loading the SharePoint module. The profile definition can be completely customized making this a viable approach for admins of other technologies, not just SharePoint.

For PowerShell this is great because it works out perfectly as built. PowerShell ISE on the other hand is still a thorn in our sides. The Scripting Guys, aka Ed Wilson and Craig Liebendorfer, wrote a terrific function that allows you to log the output pane in PowerShell ISE v1 & 2. Sadly this is not working in PowerShell v3 since there is no output pane. Leveraging that we can get part of the functionality in ISE that we get in the command-line version.

Behind the code

The solution that I came up with is in the form of a single PowerShell script that builds the following:

  • 2 folders (at the Root of C:)
    • c:PowerShellLogs will house all of the transcripts
    • c:PowerShellScripts will be the home for the scripts used to build the profiles and will be the default starting location when PowerShell opens. This way you can put all of the scripts you want to call in one place for all users and they can launch them easily.
  • check-profiles.lnk (in the All Users Start Menu Startup folder)
    • This shortcut points to a batch file in the C:PowerShellScripts folder called check-profiles.bat
  • check-profiles.bat (in c:PowerShellScripts)
    • This batch file launches the check-profiles.ps1
  • check-profiles.ps1 (in c:PowerShellScripts)
    • This PowerShell script checks to see if the user has a WindowsPowerShell folder in their My Documents folder. If it finds the folder, the script terminates. If it doesn’t find the folder it launches the create-profiles.ps1 script
  • create-profiles.ps1 (in c:PowerShellScripts)
    • This PowerShell Script creates the profiles for both PowerShell & PowerShell ISE.

Here is what I put in the PowerShell profile:

  • Set the location for PowerShell to start in to C:PowerShellScripts
  • Display a message about needing to Run as Administrator to effect changes
  • Set the path for logging the session to C:PowerShellLogs
  • Set the log name using the user context and date time stamp
  • Start the transcript
  • Display a message about waiting for the SharePoint snap-ins to load
  • Load the SharePoint snap-ins
  • Display a message that loading the SharePoint snap-in is complete and lets you know who you are running PowerShell as

Here is what I put in the PowerShell ISE profile:

  • Set the location for PowerShell to start in to C:PowerShellScripts
  • Display a message about needing to Run as Administrator to effect changes
  • Set the path for logging the session to C:PowerShellLogs
  • Load a function to set the log name using the user context and date time stamp
  • Load the function for Output-ISETranscript (the Scripting Guys code)
  • Display a message about waiting for the SharePoint snap-ins to load
  • Load the SharePoint snap-ins
  • Display a message that loading the SharePoint snap-in is complete and lets you know who you are running PowerShell as

Conclusion

While its may not be the perfect solution for PowerShell ISE that I was looking for when I set out, at the end of the day with this code I now have the ability to automatically log everything done in command line PowerShell.

Thanks to Todd Klindt, Evan Riser, Mark Rackley, and Dan Holme for talking through these use cases, reviewing some of the code, and taking differing view points on this to validate that it is a reasonable approach or not. I love being a part of a community where bouncing ideas and solutions off of peers is so easy and open.

You can find the code here:

powershell notepad

Hopefully this code will be useful to you in your day to day world.

Planning a SharePoint Saturday: A recap of #SPSNH

Planning a SharePoint Saturday: A recap of #SPSNH

We are now almost a month removed from SPSNH and it has been just enough time for the glow to start to fade and for life to start getting back to normal.  The event was wildly successful and somehow managed to receive nothing but positive reviews.  There were a few things that I noted that are worth mentioning:

1.) Drop off between registration and attendance was between 30-40%. 

2.) Doing 6 keynotes instead of 1 made the day interesting, but did not draw people in for the early sessions the way that a big name keynote might have.

3.) Planning 3 tracks (ITPro, Dev, End User) at 2 different skill levels (Beginner & Advanced) and keeping the tracks consistent in the same room so that people weren’t hunting for their next session was a BIG hit.

4.) Todd Klindt is a freaking rock star.  This isn’t something that we learned, but it was certainly reinforced.  The dude stepped up to deliver a session he had never seen until 5 minutes before when someone called in sick for the first timeslot & then presented to a standing room only group later in the day.  Todd’s heroic efforts win the booby prize with Chris McNulty coming in a close second for taking on an extra session with only a day’s notice.  The edge went to Todd because he had less prep time. 

5.) Bags and paper collateral are passé.  Give people a jump drive with digital collateral.

6.) Varying things up between 2010 & 2013 was very positive.  The people who came to hear about 2013 wanted some 2010 as well & the folks who wanted to hear about 2010 were interested in some about 2013 too.

7.) Hot coffee available all day is a MUST.

8.) Speaker gifts instead of speaker shirts.  We gave a nice warm jacket with the SPSNH & NHSPUG logos on them and I am still getting twitter comments about how much the speakers enjoy them.  Plus, SPSRED “borrowed” our idea and their speakers loved them too smile

All in all, I am happy to say that SPSNH was a great success and we are looking forward to doing it again next year.  There are things that we will look to do differently, but with a second SPSNH under our belt I think that we have a pretty good thing going up here in the “Live Free or Die” state.

My presentation from SPSNH can be found here. The slides that Todd presented on 5 minutes notice can be found here. (I had done a webinar the week before, so this was my deck from that)

My pictures from the weekend can be found here on my SkyDrive.

spflogging_32

Hooray, it’s a book!: “Developing Business Intelligence Apps for SharePoint”

Hooray, it’s a book!: “Developing Business Intelligence Apps for SharePoint”

book

Over the past year I have been spending my night’s & weekends working on a book with my co-author, Dave Feldman, and I am proud to say that we have completed our draft of “Developing Business Intelligence Apps for SharePoint”

Through the book you will learn to create dynamic Business Intelligence solutions for SharePoint, using Microsoft Visual Studio LightSwitch, SQL Server 2012, and other tools and technologies. This hands-on book shows you how to create data-rich BI applications with SharePoint faster and with more capabilities than previously possible. You’ll learn the entire process, from high-level concepts, to low-code development and deployment, to setup and configuration.

  • Quickly build a robust schema and applications with Visual Studio LightSwitch
  • Leverage PowerPivot v2 to build a business intelligence semantic model
  • Create reports with Excel Services, Report Builder, and Power View

The happy thing about our book is that we saw the CSOM model of SharePoint 2013 coming down the road and architected our solutions in the book so that they are relevant to both the 2010 & 2013 platforms (and hopefully many versions of SharePoint to come).

The book is available for pre-order on Amazon now and will be available via O’Reilly Early Release.   Dave & I will be at the SharePoint Conference in Las Vegas where O’Reilly will have a form of the book available (not quite sure if it will be a few chapters or what at that point, but there will be something!). 

I will say that Dave & I were warned by Andrew Connell & Scot Hillier when we started talking about writing this book that taking on a book project is much like having a child.  9+ months of long uncomfortable sleepless nights to give birth to something that you hope goes on to do good things in this world (I am paraphrasing a bit here… basically they both said it was going to suck something awful, but we would be happy when it was all over).  Well gents, you were right on all counts.  The fun part is that while I have 2 kids and sort of had an idea of what something like that was going to be like, Dave’s wife is pregnant with their first child and is due this SUNDAY.  Needless to say, we are glad to be done before Baby “Cookie Monster” Feldman arrives. smile

Planning a SharePoint Saturday: A recap of #SPSNH

Planning a SharePoint Saturday: A recap of #SPSNH

We are now almost a month removed from SPSNH and it has been just enough time for the glow to start to fade and for life to start getting back to normal.  The event was wildly successful and somehow managed to receive nothing but positive reviews.  There were a few things that I noted that are worth mentioning:

1.) Drop off between registration and attendance was between 30-40%. 

2.) Doing 6 keynotes instead of 1 made the day interesting, but did not draw people in for the early sessions the way that a big name keynote might have.

3.) Planning 3 tracks (ITPro, Dev, End User) at 2 different skill levels (Beginner & Advanced) and keeping the tracks consistent in the same room so that people weren’t hunting for their next session was a BIG hit.

4.) Todd Klindt is a freaking rock star.  This isn’t something that we learned, but it was certainly reinforced.  The dude stepped up to deliver a session he had never seen until 5 minutes before when someone called in sick for the first timeslot & then presented to a standing room only group later in the day.  Todd’s heroic efforts win the booby prize with Chris McNulty coming in a close second for taking on an extra session with only a day’s notice.  The edge went to Todd because he had less prep time. 

5.) Bags and paper collateral are passé.  Give people a jump drive with digital collateral.

6.) Varying things up between 2010 & 2013 was very positive.  The people who came to hear about 2013 wanted some 2010 as well & the folks who wanted to hear about 2010 were interested in some about 2013 too.

7.) Hot coffee available all day is a MUST.

8.) Speaker gifts instead of speaker shirts.  We gave a nice warm jacket with the SPSNH & NHSPUG logos on them and I am still getting twitter comments about how much the speakers enjoy them.  Plus, SPSRED “borrowed” our idea and their speakers loved them too smile

All in all, I am happy to say that SPSNH was a great success and we are looking forward to doing it again next year.  There are things that we will look to do differently, but with a second SPSNH under our belt I think that we have a pretty good thing going up here in the “Live Free or Die” state.

My presentation from SPSNH can be found here. The slides that Todd presented on 5 minutes notice can be found here. (I had done a webinar the week before, so this was my deck from that)

My pictures from the weekend can be found here on my SkyDrive.

250 USB drives to load? WHERE IS MY POWERSHELL CAPE???

250 USB drives to load? WHERE IS MY POWERSHELL CAPE???

In preparation for SharePoint Saturday New Hampshire I had to load 250 USB drives with sponsor’s digital collateral. The fun last evening was getting all of the little buggers out of their individual boxes and sealed plastic wrappers in order to make loading them a bit faster.

Today I ran out to Best Buy and purchased a pair of Belkin 7-Port USB 2.0 Powered Hubs and then sat down to “borrow” some PowerShell commands from someone on the interwebs. Sadly, I did not find a quick pre-canned script that would let me loop through my USB sticks and load them with the data. Here is what I needed my script to do:

1.) Change the name of the USB Drive to “SPSNH 2012”
2.) Copy the files and folders from the location on my hard drive to the USB Drives
3.) With a single trigger, perform the above functions on all drives inserted in the machine

In order to accomplish this I created a drivelist.txt file. Very simple text file with the list of drive letters that I were assigned to the drives when inserted. One key tip here is to make sure that there are no extraneous carriage returns after the final drive letter (this will cause an error later). The contents of the text file look like this:

1

Next I created a PowerShell script that utilized the WmiObject, WmiInstance & Item command-lets and threw in a foreach loop. The script looked like this:

2

Using this script, 2 computers & the 2 Belkin hubs I was able to load all almost 100meg on to 250 drives in just under 2 hours with distractions. Not too shabby.

I also created a second script for USB drives that are larger than 4GB that will reformat them as NTFS (or whatever format you choose) so that you can load larger files onto them, then rename the drive & copy the files in. Here is what that script looks like:

3

Hopefully this will be useful for others in the future. I would not want to be loading these things up without some form of script to assist. Below you can find a plain text version of each of these scripts that you can download and use yourself.

notepad USB Drive rename & copy script (FAT32)

notepad USB Drive format, rename & copy script (NTFS)

SharePoint Saturday New Hampshire is upon us!

SharePoint Saturday New Hampshire is upon us!

speakerbadge_newhampshire_2_4C4297A5

With only 3 days to the big event things are rapidly coming together.  The bags, speaker gifts, t-shirts, buttons, digital collateral, prizes and jump drives are all here and ready for Saturday.  I am excited for my presentation “ITPro’s taking the SharePoint 2013 “red pill” will be a ton of fun to present and should be informational as well. 

More than anything I am excited that my co-organizers and I have been able to assemble an amazing cast of speakers to come out to New Hampshire and talk about SharePoint on their own time.  We have speakers coming from Texas, Iowa, Indiana, Washington DC, and all of the New England states to share their expertise with our attendees for free. Being a regular speaker at SharePoint Saturdays for the past year and a half I take for granted all of the hard work that goes into these events and all of the people who give freely of their weekends to come out and speak at these events; it could partly be, as my colleague Mike Gilronan likes to tell people, because “Wherever there are two or more people asking about SharePoint, Jason feels obligated to show up and talk”.

I have really enjoyed helping to put this event together and am excited to see our efforts come to fruition.  If you are in the New England area and want to learn about SharePoint, please find your way up to Southern New Hampshire University on Saturday.  You won’t regret it!

To learn more and register to attend this FREE SharePoint training please visit http://www.sharepointsaturday.org/NH

Presenting “SharePoint Logging & Debugging: The Troubleshooter’s Best Friend” tonight at NYCSPUG on 3/7/2012

Presenting “SharePoint Logging & Debugging: The Troubleshooter’s Best Friend” tonight at NYCSPUG on 3/7/2012

If you are in the greater NYC area and are looking for a way to put an exclamation point on a great day of geeking out during the Virtual SQL Server 2012 launch, find your way over to the Microsoft offices at the Avenue of the Americas and come hear all about SharePoint Logging & Debugging. 

Here is the primer:

Troubleshooting and debugging issues in Enterprise SharePoint farms is a daunting task at best. SharePoint 2010 provides the tools to tackle the task, but not the roadmap. Come and join us as we lift the veil on the new and exciting features in SharePoint 2010, providing the roadmap to save you a ton of time every time you troubleshoot or debug an issue in SharePoint. Reclaim your evenings and weekends once and for all by taming the SharePoint debugging beast!

There will be food and drinks provided, and a SharePint following the event that promises to be a great time.  I have even heard that there will be some other out-of-towners making an appearance.

If all of that isn’t enough to rope you in, I will be giving away a Lync certified Plantronics Voyager PRO UC.

You can also check out my deck here: http://slidesha.re/wxIvNe

Hope to see you there!

spflogging_32

Holy time gap in posting!

Holy time gap in posting!

It has been almost 6 weeks since my last post and it is time to bring to light what has been going on in my world during that time. 

While I am not someone who discusses my employer regularly on my blog, I joined Sentri 6 months ago and couldn’t be happier.  Especially in light of recent developments.  Some of you may have noticed the press release, twitter storms, webcasts, etc about Sentri’s acquisition of the KMA SharePoint Practice.  Over night my small practice grew to more than 4 times its size and was endowed with even more dynamic, and highly talented people. 

Anyone who has ever lived through the M&A process can tell you that it is a nail biting & hair raising process as you never know if things are going to move forward or if Murphy is going to stick his head up and yell “GOTCHA!”

In the weeks since my last posting life has been extremely interesting and exciting preparing for and then finally working through the details of integrating two different SharePoint Practices into one.

Needless to say since I am writing this post, we are in the lucky 17% that went into the M&A process and came out the other side smiling.  I am sincerely thrilled to be working closely with Mike Gilronan (check out his take on this here), Derek Cash-Peterson, and the entire Sentri SharePoint team.

As for my commitment to the SharePoint community, it remains as strong as ever.  I have added a Speaking Engagements section to my blog so that you can find out where and when I will be speaking next.  This week I will be speaking at the NYC SPUG on Wednesday March 7th, 2012 at 6pm.

And now back to posting content…. smile

Putting a bow on an amazing year of SharePoint

Putting a bow on an amazing year of SharePoint

Last week I had the honor of presenting “Heavy Metal PowerPivot Redux” to the San Antonio SharePoint Users Group.  My slide deck from that session can be found here: http://www.slideshare.net/SentriInc/sentris-saspug-deck-heavy-metal-power-pivot-redux

The SASUGers were a great group of folks to present to and the location was tremendous.  We were hosted by Jeff Deverter at the RackSpace facility in Eastern San Antonio.  They purchased the Windsor Park Mall and have converted it into their offices.  It was completely wild experience touring a mall that I had shopped at previously and finding that it was now a state of the art office facility, complete with slide.

Here are a few pictures from the evening:

From the presentation, & you have to love an SPUG that provides beer at the meeting!

a b

Touring the RackSpace Facility

c d

Time to ride the slide!

e f

Yes, I got stuck…

g

A post-slide group photo with the early birds

h

Needless to say it was a terrific evening and I can’t wait to come back and speak again at SASUG.  Thanks to Tom Resing, Jessica Saucedo, and Jeff Deverter for all they did to make it possible.

#SPSDenver Wrap-up

#SPSDenver Wrap-up

banner

I was honored to be a two-day speaker at SPSDenver this past weekend and had a marvelous time doing so.  The conference was well organized, properly planned, and extremely well attended.  Credit to Clayton Cobb and his team for putting on such a great event.  From the care of ensuring that they understood every issue that an attendee had to making sure that the fragile egos of the speakers were well cared for to making sure that every sponsor got the most out of the event, they really had their act together.  That was all before we even got to ShareSki!

Every time I travel for SharePoint I meet new, interesting people and it reinforces my opinion that the SharePoint Community is the greatest group of people with a common technology interest anywhere.  It is always fun to get to know more people in our world and I am humbled to be a part of it.

Needless to say, I was impressed by SPSDenver and am looking forward to returning next year if they are kind enough to have me back.

For those who are looking for the SPSDenver slide decks please find them below:

SharePoint Logging and Debugging

SharePoint Performance Best Practices from the Field