Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Creating New PowerShell Projects

Posted on May 17, 2016

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.

Manage and Report Active Directory, Exchange and Microsoft 365 with
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:

image

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.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

5 thoughts on “Creating New PowerShell Projects”

  1. Ralf says:
    May 17, 2016 at 9:12 am

    Cool! Thx, I’ll definitely look into it!

  2. Rod Stewart says:
    May 19, 2016 at 10:12 am

    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!

    1. Jeffery Hicks says:
      May 19, 2016 at 11:15 am

      Yeah, I found that bug as well yesterday. Haven’t had a chance to update the function but will do so now.

  3. Wolfram Zimmermann says:
    June 2, 2016 at 6:10 am

    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.

  4. Jeffery Hicks says:
    July 15, 2016 at 9:43 pm

    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.

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d