Skip to content

Instantly share code, notes, and snippets.

@RamblingCookieMonster
Last active September 22, 2021 16:22
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save RamblingCookieMonster/12c4eb61dde8b2703184 to your computer and use it in GitHub Desktop.
Save RamblingCookieMonster/12c4eb61dde8b2703184 to your computer and use it in GitHub Desktop.
zModuleBuild.ps1
# We cloned our project to C:\sc\PSStackExchange
$Path = 'C:\sc\PSStackExchange'
$ModuleName = 'PSStackExchange'
$Author = 'RamblingCookieMonster'
$Description = 'PowerShell module to query the StackExchange API'
# Create the module and private function directories
mkdir $Path\$ModuleName
mkdir $Path\$ModuleName\Private
mkdir $Path\$ModuleName\Public
mkdir $Path\$ModuleName\en-US # For about_Help files
mkdir $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 $ModuleName.psm1 `
-Description $Description `
-PowerShellVersion 3.0 `
-Author $Author `
-FormatsToProcess "$ModuleName.Format.ps1xml"
# Copy the public/exported functions into the public folder, private functions into private folder
@ngetchell
Copy link

There are two places where you hard coded PSStackExchange instead of using $ModuleName. I don't think I can do a merge request on a gist so here is the fixed code.

https://gist.github.com/ngetchell/ec930f1dfcdd7450d1ca

@ericjaystevens
Copy link

Thanks for the tool, i find the structure you propose very useful.

I agree with ngetchell, that lines 17 and 18 could be more reusable. But replacing with just $ModuleName fails because the \ is processed as an escape character. Consider using $($moduleName), Here is the link to my fork if you find it useful.

https://gist.github.com/ericjaystevens/03a23ee76bd1992f9fb297dc8122351b

@RamblingCookieMonster
Copy link
Author

Apparently gists don't have notifications in place - thank you both!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment