I've been writing scripts since the early days of DOS batch files. Like many of you I simply stick them all in a folder and move on to the next project. Most of my work is just for me or writing projects so this methodology worked just fine for me. But I need to live in your world and in 2016 that means new tools and processes. For many people developing PowerShell tools, modules, and DSC resources this means some sort of versioning system and testing. This is especially true if you are moving into the world of DevOps.
ManageEngine ADManager Plus - Download Free Trial
Exclusive offer on ADManager Plus for US and UK regions. Claim now!
So I've been learning and using Git and Pester with my new projects. As I find myself revisiting older projects I'm also retrofitting them with a Git repository and a few Pester tests. A major benefit for me is that every time I do this, I learn a bit more about these tools. I've taken some of this knowledge and created a project provisioning script I call New-Project. I know some of you have something similar.
The script takes a top level folder name, I use a default value of C:\Scripts, and a project name. Typically this will be the name of a module. The script creates a folder with the project name and then runs through a set of initialization steps:
- creates and commits an empty Git repository (master)
- creates and commits Dev branch
- checks out the Dev branch
- creates a README.md file outline
- creates the outline of a project .ps1 file
- creates a Tests subfolder
- creates the outline of Pester test file.
So I might use it like this:
You need to have the Git command line tools installed and the Pester module. I am still debating a few additional features such as integrating the project with my GitHub repositories and including a license file. Maybe even an option to generate a module manifest. Perhaps you'll try it out and suggest a few other new features. The file is stored as a Gist on GitHub.
I hope you'll give it a whirl and let me know what you think.
Cool! Thx, I’ll definitely look into it!
Hey Jeffrey, I really dig the function and the idea behind it, but I had an issue with running the Pester tests using this function.
Basically, with the Pester tests being placed into the Tests subdir, I had to change line 130 from:
`$sut = (Split-Path -Leaf `$MyInvocation.MyCommand.Path) -replace ‘\.Tests\.’, ‘.’. ‘`$here\`$sut’
to:
`$sut = (Split-Path -Leaf `$MyInvocation.MyCommand.Path) -replace ‘\.Tests\.’, ‘.’
. “`$here\..\`$sut”
I’m not sure if this is the most appropriate solution, but it seems to work for now.
Thanks again!
Yeah, I found that bug as well yesterday. Haven’t had a chance to update the function but will do so now.
Hi Jeff,
I follow you on twitter for a while now..
I appreciated your script pretty much and therefore reworked it a bit implementing ideas from http://keepachangelog.com and https://devblackops.io/building-a-simple-release-pipeline-in-powershell-using-psake-pester-and-psdeploy/ creating a version of “new-project” that creates a basic module structure with manifest and psm1 and the necessary files for a basic build process.
It grew a little too much to paste here (about 320 lines – most of it are the here-strings for the base-files) and still needs some polishing, but it works pretty fine.
If you’re interested, please let me know.
new version as of July 15, 2016 that includes an About topic outline, a license.txt file and a few other changes. Code on GitHub is always the most current.