Browsed by
Tag: How to

How to: Activate Desktop Experience in Windows Server 2012

How to: Activate Desktop Experience in Windows Server 2012

I ran into an issue where I needed to active that Desktop Experience in on Windows Server 2012 and found that it was not in the same place that I was expecting it to be from previous versions. Figured that this might help some people.

Desktop Experience is required to be running if you are going to utilize OneNote, which when working in a demo server environment can be very useful. There are some DLLs that are not accessible unless you are running the Desktop Experience that are critical to applications like Snagit & Camtasia.

Wizard Driven:

To active the Desktop Experience go Server Manager | Local Server | Manage | Add Roles & Features

1

Once in the wizard under Features drill into the User Interfaces and Infrastructure and select Desktop Experience. This will active the Ink and Handwriting Services & Media Foundation features as well.

2

After installation the server requires a reboot to complete and will make the features active for accessing.

PowerShell:

From a PowerShell prompt running as Administrator use the following command:

3

During execution you will see the following:

4

Once complete you will be notified that you need to reboot the server:

5

Enjoy!

 notepad active Desktop Experince script

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.

How to: Create a OneNote help file out of a PowerShell Module

How to: Create a OneNote help file out of a PowerShell Module

Being an ITPro in the current day and age I write a decent amount of PowerShell. Since I am not always on a server that has the SharePoint PowerShell modules installed most of my time on TechNet is spent basically reading the help files of specific modules to validate syntax, flags or review examples. This can become a bit of a pain after a while so I thought it would be nice to have a OneNote notebook on my SkyDrive that I could sync to my laptops or access in the cloud where I could search more easily and have all of my cmdlets at my fingertips.

Here is how I accomplished this:

Select the module. For this example I used the Microsoft.SharePoint.PowerShell module, however this will work with any PowerShell module.

Run the following command to get an output of the cmdlets in the module:

1

Opening in Excel will give you the best opportunity to grab what you need. Column K in this particular output will list all of the cmdlets names.

2 

Grab just that column and copy it to a text file called “cmdlets.csv”.

Next use the following PowerShell command to create an ANSI output file for each of the help files in the module.

3

For this module it created 771 individual text files. Using the OneNote 2010 Text Importer from John Guin I was able to create a single OneNote file that contains all of the help for the entire SharePoint 2013 PowerShell module that is now searchable in a faster and easier way. One caveat, I had to use OneNote 2010 for the importer to work properly.

Not sure if this will be helpful for anyone else, but I use it all the time when writing PowerShell Code.

4

I will endeavor to keep this up to date, but since I just explained how to accomplish this, if I slip up you can perform the actions yourself.

You can get download the notebook here: http://sdrv.ms/X7PqqI

notepad  get cmdlets in the module script

notepad  create ANSI output file for each of the help files in the module script

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

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)

How to: Run PowerShell ISE as Administrator under alternate credentials

How to: Run PowerShell ISE as Administrator under alternate credentials

Coming from a security focused AD background I prefer to have the Managed Service Accounts OU locked down with a GPO restricting interactive logon to a server. This helps avoid service accounts becoming compromised and being taken advantage of in attacks.

Having an ISE is especially helpful when you are doing SharePoint work on the farm and while I am a big fan of PowerShell, running straight at the command line is often a pain. Rather than installing one of the terrific third party solutions out there for an Integrated Shell Environment I try to only install the PowerShell ISE.

As we know, there are something that you cannot do unless you are running in the context of the Farm Administrator account. There is code out there that will let you elevate your PowerShell script and run in the context of a different user, but I really wanted to be able to open PowerShell ISE as the farm account so that I can run parts of a script at a time, or rerun specific lines.

Here is the code that I compiled that allows me to launch PowerShell ISE as the Farm Admin account:

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA 0

# Farm account name
$farmAccountname =
“domainservice_account”

# Load the Farm Account Creds
$cred = Get-Credential
$farmAccountname

# Create a new process with UAC elevation S
tart-Process
$PsHomepowershell.exe -Credential $cred -ArgumentList “-Command Start-Process $PSHOMEpowershell_ise.exe -Verb Runas -Wait

Once your PowerShell ISE window is launched you can run the following code to validate that you are running as the user that you are expecting:

[Security.Principal.WindowsIdentity]::GetCurrent().Name

Great you learned some more neato PowerShell, but why do I need to use a PowerShell command for this?

You may be asking why wouldn’t I just do a simple “SHIFT+Right Click” and “Run as different user” rather than resorting to a PowerShell solution. The answer is that doing that does not give you the runAs Administrator privileges that we need to do so many of SharePoint’s PowerShell Functions.

Smarty Pants.

powershell PowerShell launch code

notepad Text launch code

powershell User Context validation code