I’ve been assisting a colleague over the last couple of years to get the on and offboarding process automated within my company.
my colleague used to create 1 file to check if all the directory’s are in place 1 file to do all the modifications required on the incoming csv file 1 file for everything that needed to be done in AD O365 AzureAD ect. and it all works.
my question is since it’s very difficult to do maintenance (I guess there are at least 30+ ps files) would it be better to create just 1 large powerschell script with everything included, or just keep the original files and leave it as is?
If you create just 1 file what would be the ideal setup in terms of where to place the different functions and how make use of functions to avoid all the repeating tasks like creating csv files adding columns to csv files ect?
Since this topic is actually not a technical topic you are asking for opinions. That’s actually not a good idea in a forum.
The answer depends heavily on the rules you have in your company or your departement or your team and on yours and the personal preferences of your collleagues.
Here are some of my opinions or how I used to handle those topics.
- If something is working just fine and there’s no need to change anything - I won’t change it.
- If I create something new I try to make it as interoperable and as general as possible. So I can re-use it later on.
- I try to follow common best practices and style guides to make it easier for my future me and for colleagues to read, to understand and to maintain the code if necessary.
- I try to work by the KISS principle.
- I try to create functions in modules instead of script specific functions to make them easily re-usable and easily discoverable by my colleagues.
In your particular case I’d maybe create a “controller script” calling all these other 30+ “worker scripts” if needed with the proper parameters.
Concur with @Olaf, all supporting functions\scripts should be in a Powershell Module. Import the module and then there would a single script that would execute the functions, in order, with error handling. It provides a modular structure that is much easier to support and troubleshoot than a single gigantic script with everything. Seen many companies build a “MyCompanyTools” module that has a compilation of common functions to be used in day-to-day administration and supporting scripts for automation.