Skip to content

Instantly share code, notes, and snippets.

@markwragg
Forked from RamblingCookieMonster/zModuleBuild.ps1
Last active March 26, 2023 03:13
Show Gist options
  • Save markwragg/ce25b18b1322f0f8a25f685d0a06d5a0 to your computer and use it in GitHub Desktop.
Save markwragg/ce25b18b1322f0f8a25f685d0a06d5a0 to your computer and use it in GitHub Desktop.
A PowerShell script for creating the default scaffolding and files for a new PowerShell module.
[cmdletbinding()]
Param(
[Parameter(Mandatory=$True)]
[string]$ModuleName,
[string]$Path = "C:\Users\$env:UserName\Documents\Code\$ModuleName",
[string]$Author = 'Mark Wragg',
[string]$Description = '',
[version]$PSVersion = '3.0'
)
If(test-path $Path) { Throw "The path '$Path' already exists!" }
# Create the project directory
New-Item -ItemType Directory -Path $Path
# Create the module and private function directories
New-Item -ItemType Directory -Path $Path\$ModuleName
New-Item -ItemType Directory -Path $Path\$ModuleName\Private
New-Item -ItemType Directory -Path $Path\$ModuleName\Public
New-Item -ItemType Directory -Path $Path\$ModuleName\en-US # For about_Help files
New-Item -ItemType Directory -Path $Path\Tests
#Create the module and related files
New-Item "$Path\$ModuleName\$ModuleName.psm1" -ItemType File
New-Item "$Path\$ModuleName\$ModuleName.Format.ps1xml" -ItemType File
New-Item "$Path\$ModuleName\en-US\about_$ModuleName.help.txt" -ItemType File
New-Item "$Path\Tests\$ModuleName.Tests.ps1" -ItemType File
New-ModuleManifest -Path $Path\$ModuleName\$ModuleName.psd1 `
-RootModule $Path\$ModuleName\$ModuleName.psm1 `
-Description $Description `
-PowerShellVersion $PSVersion `
-Author $Author `
-FormatsToProcess "$ModuleName.Format.ps1xml"
# Copy the public/exported functions into the public folder, private functions into private folder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment