0

Scripts, Functions, Modules, DSC resources – Pick the right option!

Body:
This may become a bit of a controversial post and that in some parts in fully intentional!

This really should be giving PowerShell Users (looking at the admins of us all that just use PowerShell as if it were VBScript with no real community or practices) the opportunity to understand the problems with what they are outputting to “get it done” at this current time.

My issue is that over the last 9 years PowerShell has become a crucial tool to be able to manage at scale (and also singular machines too) and yet there are still some truly awful examples being posted each day on how to solve what is most times a simple issue which has already been resolved by others

This needs to change and change very quickly otherwise we will be battling inefficient and quite frankly useless code for many many years to come (look at examples regarding Server Side SharePoint Code for SharePoint 2007 on either CodePlex or StackOverflow– which can in cases still be used in SharePoint 2013 & even SharePoint 2016)

Ok so perhaps I have some biased views and this is all with very good reason I may add. In 10 years time my son will be at age where he will be looking at making his decision on where he wants to take his career (hoping IT). Now I may have a very narrow view but this is mainly because we are at a point where we can ensure that we have only the best examples that ensure that we can be as modular as possible in future as to allow for the highest reusability across platforms.

In comes the need for the community to step up and work on making sure that we extend only the best Modules which we ensure are hosted on the PowerShell Gallery for ease of installation and discoverability and that we have the modules all open source developed via repo’s hosted on GitHub. This ensures consistency to the development of them and really allows the wider community to contribute back to items that affect them day to day.

In 5 years time I would love to see there be multiple communities around the differing technologies that we have in the Microsoft world that reach out to the PowerShell Community to help ensure that outputted code is fully reusable and as modular as possible whilst ensuring that it is the most performant possible. I suppose my reason for thinking this would be that I can see the IT Pro/DevOps engineers of future being fully OS & application independent.

We are at a golden age to do this now that there is the supporting technology out there to enable us to do this although it could be argued that the technology has been around for well over 10 years but it is now much more accessible to all, Items like multiple person Video & Voice Conferencing with applications like Skype, Skype for Business, Cisco Webex & GoToMeeting, Instant Messaging across platforms including on mobile with Skype for Business, WhatsApp, Telegram, Slack etc and code sharing platforms including GitHub, GitLab, BitBucket etc

So firstly I would like to suggest that if you are a user of PowerShell for applications like SharePoint, Exchange, SQL to name a few and you are finding that you are writing lots of PowerShell to get a task done then I would suggest that first thing you should do is to search the PowerShell Gallery to see if there is an existing module out there that has that functionality that you require – there is the ability to search for Function Names but not a detailed search but I have raised an issue on Connect for this issue so hopefully this will be fixed soon – you can vote for it at http://bit.ly/PSFindModule

But back on to the point of the blog post and this is where it is likely to get a bit more controversial.

Firstly, we need to go back to basics and understand what we are scripting and why we are scripting it before we determine the method that we are going down.

No matter how many times we are looking to run a script we should be looking to modularise it into small reusable sections that we call in the correct way for use later on – by this I mean that if we aren’t ensuring a configuration then we shouldn’t be creating DSC Resources we should be creating functions within modules – examples for this would be for methods where there is no real need for having a Get, Set & Test functionalities – this is especially true with services that use Web API’s that invoke REST Methods that don’t really return a corresponding Object back to the user and some examples of this for me includes posting to Social Media like Twitter & Slack – these should be written as a function within a module as there is no benefit in my opinion to create a DSC resource just because you can create one.

So for items that you need to ensure are consistent like server configurations then you should be making DSC resources, if not then please don’t make a resource as in my opinion its making a resource for the sake of making a resource which is not really useful or beneficial to the community as a whole as it will start to muddy the waters on when to use the functionalities that we have available to us and we need to simplify the way we write the scripts of the future for the better – that means the best performant scripts that are able to be built using reusable blocks that do Just Enough Action with Just Enough Output that can then be reused with other functions and therefore other technologies.

 

 

 

 

Published: 03/11/2015 15:15


Leave a Reply