In this blog post I will be covering 2 very important topics both related to developing cool PowerShell scripts for your SharePoint 2013 farm environments. The first topic that will be covered by this post is the ability to create Graphical User Interfaces with Powershell. You need to understand that PowerShell is built on top of .NET, and that because of this, a Powershell script can import and use any .NET entity, including those contained in the System.Windows.Forms namespace. This then gives us the ability to create graphical user interfaces as if we were simply creating a new Windows Form Application.
The second topic I want to be covering, is the ability to use PowerShell to interact with SharePoint 2013 using the Client Side Object Model (CSOM). Just like for the graphical user interface, we can import assemblies from the SharePoint .NET CSOM and use them to interact with remote SharePoint 2013 environments. This is actually very Powerful, but requires you to understand how the SharePoint Client Side Object Model works. It does require some good development knowledge in order to use it. My book “Beginning PowerShell for SharePoint 2013” makes a brief reference to this, but doesn’t cover it in any real details. This method is especially useful when wanting to interact with Office 365 using PowerShell.
Alright, now that I’ve set the table, let’s dive into the content of this post. Assume that you want to create a new visual interface, that let’s users input the URL of a remote SharePoint 2013 farm, and that retrieves the name of all the lists contained at that web level. Using PowerShell, you could easily build a script that will automatically generate a simple GUI, and make calls to the SharePoint CSOM. Figure 1 below shows the end result of my script. Users are asked to input the remote SharePoint environment’s URL in the text box at the top, and when they click on the Connect button, the PowerShell script will automatically connect and retrieve all the lists using the Client Side Object Model.
Figure 1 – Results of the PSGUI Powershell script
Below is the PowerShell code used to create this powerful tool. It can be run from any machine that has PowerShell v3 and higher, but requires that the user running it, as read access to the destination site specified in the URL box. Enjoy!