What is Powershell? (Hint: it’s not that power-up in Mario Cart dividing friendships)
Development SharePointThe first time someone told me to use PowerShell I almost laughed in their face, thinking it was an outdated tool that reminded me of my first computer running on DOS. I was wrong. Very wrong.
Since then I started to dabble here and there, and fast forward about a year later and I’m a full convert. PowerShell takes a massive part of my daily activities as a web developer, particularly in the realm of SharePoint.
So what is PowerShell? From my use and experience, it’s an object-orientated command environment with scripting language that utilises small commands called cmdlets. It’s built on the .NET Framework and used to administer Microsoft products and applications from Windows, Microsoft Office, server and network administration to online services such as Office 365 and Active Directory.
Before PowerShell was in my life, my first thought when trying to solve a problem would be to spin up a new C# project, write out the application code across various files and config, compile, and run.
Now it’s as easy as opening a PowerShell console and stringing together a few cmdlets. Aside from what gets packaged with PowerShell, there are plenty of libraries of cmdlets available that can be installed as PowerShell modules. One of the modules that has become very useful to me in managing SharePoint sites is the PnP PowerShell module.
PowerShell scripts can also be created that combine cmdlets and any processing required that can be run in a single command as shown here:
These scripts can be as simple or as complicated as you can come up with. A script can run cmdlets and call other scripts, which can also call other scripts and cmdlets and so on. Scripts can also contain functions that can be called and referenced in other scripts too.
Some commands also have aliases, so you can write less, for example in the screenshot above, “Where-Object” can be replaced with just “?”, and “Select-Object” can be replaced with “select”.
Oh, and did I mention PowerShell isn’t case sensitive? So again, in the above script, “get-pnplist” and “format-table” would work.
It’s very easy for what starts as a simple script to become a Frankenstein of multiple scripts with logic scattered across files if you’re not careful. I could go on about best practices for developing PowerShell scripts, but that’s an entirely new topic on its own that I’ll write about another time.
These days, when I need to get something done, one of my first questions is “how can I do this using PowerShell?”. Sync profile data from AD to SharePoint? PowerShell. Provision lists to 20 SharePoint sites? PowerShell. Rename all files in a directory to follow a standard naming convention? PowerShell. Mop the floors after the dog has tracked mud through the house after a storm?Still working out the logistics…
PowerShell is simple and flexible enough to meet the needs of a large range of tasks, yet robust enough to tackle complex problems and infrastructure.