|
1 | 1 | # PowerShellModuleStarterKit
|
2 |
| -A starter kit for new PowerShell script modules including unit tests. |
| 2 | +A starter kit for new PowerShell script modules. |
3 | 3 |
|
4 |
| -Contains a basic .psd1 (manifest) and .psm1 (root module), class examples, function examples, and unit tests. |
| 4 | +This repository demonstrates how to organize a module and accomplish a few common tasks like public vs private functions, unit tests, working with classes, and more. |
5 | 5 |
|
6 |
| -### Prerequisites |
| 6 | +## Features |
| 7 | +* Public and private functions. |
| 8 | +* Unit testing with the Pester framework. |
| 9 | +* PowerShell v5 classes (accessible inside and outside the module scope). |
| 10 | +* Module private data (for constants and caching). |
| 11 | +* Referencing static resource files. |
| 12 | +* Referencing external libraries. |
7 | 13 |
|
8 |
| -In order to run the unit tests, you need the Pester test framework (https://github.com/pester/Pester). |
| 14 | +## Setup |
| 15 | +1. Clone the repository to your local computer. |
| 16 | +2. Open PowerShell (as an administrator). |
| 17 | +3. Install the [Pester](https://github.com/pester/Pester) framework: |
| 18 | +``` powershell |
| 19 | +Install-Module -Name Pester -MinimumVersion 4.6.0 -Scope AllUsers -Force -SkipPublisherCheck |
| 20 | +``` |
| 21 | +4. Add this starter kit module to the PSModule path. |
| 22 | +***Note: This assumes you have cloned the repository to C:\Source. Update the path if this isn't correct.*** |
| 23 | +``` powershell |
| 24 | +$repoDirectory = 'C:\Source\PowerShellModuleStarterKit' |
| 25 | +$existingPaths = $ENV:PSModulePath |
| 26 | +$newPaths = "$repoDirectory;$existingPaths" |
| 27 | +$scope = [System.EnvironmentVariableTarget]::Machine |
| 28 | +[System.Environment]::SetEnvironmentVariable('PSModulePath',$newPaths,$scope) |
| 29 | +``` |
9 | 30 |
|
10 |
| -Once Pester is installed and in your PSModule path, run the Invoke-Pester cmdlet (no args) from the root of the repository. It will find and run the tests for you. |
| 31 | +## Load the module |
| 32 | +``` powershell |
| 33 | +Import-Module -Name SampleModule |
| 34 | +``` |
11 | 35 |
|
12 |
| -### Notes |
13 |
| - |
14 |
| -This module can be loaded by calling Import-Module on either the module manifest (.psd1), or the root module (.psm1) file. |
15 |
| - |
16 |
| -For the sake of easy unit testing, the .psm1 file is referenced for test imports. This is because the private functions and (non-exportable classes) are easily found and loaded. |
| 36 | +## Run the unit tests |
| 37 | +***Note: This assumes you have cloned the repository to C:\Source. Update the path if this isn't correct.*** |
| 38 | +``` powershell |
| 39 | +cd 'C:\Source\PowerShellModuleStarterKit\SampleModule' |
| 40 | +Invoke-Pester |
| 41 | +``` |
0 commit comments