Creating a Graphical User Interface with PowerShell for SharePoint

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!



$form = New-Object
$form.Height = 360
$form.Width = 500
$form.Text = “Power SharePoint Console”

$btnConnect = New-Object System.Windows.Forms.Button
$btnConnect.Height = 25
$btnConnect.Width = 75
$btnConnect.Left = 35
$btnConnect.Top = 10
$btnConnect.Text = “Connect”

$txtUrl = New-Object System.Windows.Forms.TextBox
$txtUrl.Width = 200
$txtUrl.Top = 10
$txtUrl.Left = 120

$txtResults = New-Object System.Windows.Forms.TextBox
$txtResults.Multiline = $true
$txtResults.Width = 450
$txtResults.Height = 250
$txtResults.Left = 16
$txtResults.Top = 50
$txtResults.ScrollBars = [System.Windows.Forms.ScrollBars]::Vertical

# SharePoint Specific
Function GetInfo($url)
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$web = $ctx.Web
$lists = $web.Lists

$stringLists = “Lists in the specifiec web: `r`n”
for($i = 0; $i -lt $lists.Count; $i++)
$curList = $lists[$i]
$stringLists += $curList.Title + “`r`n”
$txtResults.Text = $stringLists
[System.Windows.Forms.MessageBox]::Show(“Lists Acquired Successfully!”)


Identify SharePoint Farm Version

11infoicon.pngWith SharePoint, there is a very handful tip I keep forgetting about, and that let’s you easily determine the exact build number of any given SharePoint farm. The platform exposes a Configuration Link Endpoint that let’s you get this information by simply appending /_vti_pvt/service.cnf to any web URL on your site. For example, to determine the current build version of my site (which will change frequently due to it being hosted on Office 365), you can simply access You should see something on screen that looks like the following:


This indicates that my SharePoint farm currently is running on version of SharePoint online.