I'm trying to sort out CI builds using TFS/VSTS that use packer and other tools.
Currently I use packer validate to prove that its working ok, but there appeared to be no way of validating the answer files for windows other than loading them into the AIK.
I found a blog post here http://schneegans.de/computer/unattend-schema/ which suggested how to get at the schema, so I set about knocking some powershell functions together to extract the schema programatically (I'm not posting the schema as I dont want to start having to read too many licence agreements) and then use this to validate the XML against what is in the schema.
I appreciate there is a fair bit of refactoring that could be done and no pester tests - but I've cobbled / pasted these together in this format for the purposes of the internet and removed logic that is only appropriate for my environment.
Not saying they will be perfect or usuable in every locale.. Works on my machine though.
script is located here https://gist.github.com/davidwallis3101/48454cb6c17c988de43b5ea17089ea6f
I try to specialise in doing the out of the ordinary stuff (A Challenge!) - And generally making life as easy as possible using any of the technologies within reach without having to re-invent the wheel where possible! Technologies and products can include -> .NET, VBS, Powershell, DSC, Systems Center, NetApp, VMWare, Windows Server, Linux, Python, Microcontrollers and others!
Thursday, 9 May 2019
Tuesday, 2 April 2019
Refactoring PSM1 based modules into seperate ps1 files
A lot of my old powershell modules have grown to be quite big and unweildly.
At work we have now standardised on using PSAKE to create them and use a structure that has a public and private set of folders that contain ps1 files that make up the modules functions. These are automatically dot sourced when the module loads.
I'm not going to claim credit for doing it that way, its based on some complex googling, or maybe just plain luck.
In an effort to refactor and make some of these more readable, supportable, easier to test using pester etc etc.. I've knocked up a quick and dirty script for 'refactoring' the module into seperate files.
It's not perfect but it was spend a little time writing a script to do it, rather than spending the time manually in VSCode or Notepad++
The code uses powershell's Abstract Syntaxt Tree / Language Parser. it might help someone, it might not :)
Code is here: https://gist.github.com/davidwallis3101/58de8462bf37c8683b377cb0c7a5a95b
At work we have now standardised on using PSAKE to create them and use a structure that has a public and private set of folders that contain ps1 files that make up the modules functions. These are automatically dot sourced when the module loads.
I'm not going to claim credit for doing it that way, its based on some complex googling, or maybe just plain luck.
In an effort to refactor and make some of these more readable, supportable, easier to test using pester etc etc.. I've knocked up a quick and dirty script for 'refactoring' the module into seperate files.
It's not perfect but it was spend a little time writing a script to do it, rather than spending the time manually in VSCode or Notepad++
The code uses powershell's Abstract Syntaxt Tree / Language Parser. it might help someone, it might not :)
Code is here: https://gist.github.com/davidwallis3101/58de8462bf37c8683b377cb0c7a5a95b
Subscribe to:
Posts (Atom)