Skip to content

Commit 430841c

Browse files
authored
📄 Add many additional help examples
1 parent c03d87e commit 430841c

File tree

1 file changed

+106
-5
lines changed

1 file changed

+106
-5
lines changed

ModuleFast.psm1

Lines changed: 106 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,121 @@ function Install-ModuleFast {
3232
.SYNOPSIS
3333
High performance, declarative Powershell Module Installer
3434
.DESCRIPTION
35-
ModuleFast is a high performance, declarative PowerShell module installer. It is designed with no external dependencies and can be bootstrapped in a single line of code. It is ideal for Continuous Integration/Deployment and serverless scenarios where you want to install modules quickly and without any user interaction. It is inspired by pnpm and other high performance declarative package managers.
35+
ModuleFast is a high performance, declarative PowerShell module installer. It is optimized for speed and written primarily in PowerShell and can be bootstrapped in a single line of code. It is ideal for Continuous Integration/Deployment and serverless scenarios where you want to install modules quickly and without any user interaction. It is inspired by pnpm and other high performance declarative package managers.
3636
3737
ModuleFast accepts a variety of familiar PowerShell syntaxes and objects for module specification as well as a custom shorthand syntax allowing complex version requirements to be defined in a single string.
3838
3939
ModuleFast can also install the required modules specified in the #Requires line of a script, or in the RequiredModules section of a module manifest, by simplying providing the path to that file in the -Path parameter (which also accepts remote UNC, http, and https URLs).
4040
41+
---------------------------
42+
Module Specification Syntax
43+
---------------------------
44+
ModuleFast supports a shorthand string syntax for defining module specifications. It generally takes the form of '<Module><Operator><Version>'. The version supports SemVer 2 and prerelease tags.
45+
46+
The available operators are:
47+
- '=': Exact version match. Examples: 'ImportExcel=7.1.0', 'ImportExcel=7.1.0-preview'
48+
- '>': Greater than. Example: 'ImportExcel>7.1.0'
49+
- '>=': Greater than or equal to. Example: 'ImportExcel>=7.1.0'
50+
- '<': Less than. Example: 'ImportExcel<7.1.0'
51+
- '<=': Less than or equal to. Example: 'ImportExcel<=7.1.0'
52+
- ':': Lets you specify a NuGet version range. Example: 'ImportExcel:(7.0.0, 7.2.1-preview]' For more info: https://learn.microsoft.com/en-us/nuget/concepts/package-versioning#version-ranges. Wilcards are supported with this syntax e.g. 'ImportExcel:3.2.*' will install the latest 3.2.x version.
53+
54+
ModuleFast also fully supports the ModuleSpecification object and hashtable-like string syntaxes that are used by Install-Module and Install-PSResource. More information on this format: https://learn.microsoft.com/en-us/dotnet/api/microsoft.powershell.commands.modulespecification?view=powershellsdk-7.4.0
55+
56+
-------
57+
Logging
58+
-------
59+
Modulefast has extensive Verbose and Debug information available if you specify the -Verbose and/or -Debug parameters. This can be useful for troubleshooting or understanding how ModuleFast is working. Verbose level provides a high level "what" view of the process of module selection, while Debug level provides a much more detailed "Why" information about the module selection and installation process that can be useful in troubleshooting issues.
60+
61+
-----------------
62+
Installation Path
63+
-----------------
64+
ModuleFast will install modules to the default PowerShell module path on non-Windows platforms. On Windows, it will install to %LOCALAPPDATA%\PowerShell\Modules by default as the default Documents PowerShell Modules folder has increasing caused problems due to conflicts with document syncing programs such as OneDrive. You can override this behavior by specifying the -Destination parameter. You can also specify 'CurrentUser' to install to the legacy Documents PowerShell Modules folder on Windows only.
65+
66+
As part of this installation process on Windows, ModuleFast will add the destination to your PSModulePath for the current session. This is done to ensure that the modules are available for use in the current session. If you do not want this behavior, you can specify the -NoPSModulePathUpdate switch.
67+
68+
In addition, if you do not already have the %LOCALAPPDATA%\PowerShell\Modules in your $env:PSModulesPath, Modulefast will append a command to add it to your user profile. This is done to ensure that the modules are available for use in future sessions. If you do not want this behavior, you can specify the -NoProfileUpdate switch.
69+
70+
.PARAMETER WhatIf
71+
If specified, will output the installation plan to the pipeline as well as the console. This can be saved and provided to Install-ModuleFast at a later date.
72+
73+
.EXAMPLE
74+
Install-ModuleFast 'ImportExcel' -PassThru
75+
76+
Installs the latest version of ImportExcel and outputs info about the installed modules. Remove -PassThru for a quieter installation, or add -Verbose or -Debug for even more information.
77+
78+
--- RESULT ---
79+
Name ModuleVersion
80+
---- -------------
81+
ImportExcel 7.8.6
82+
4183
.EXAMPLE
42-
Install-ModuleFast 'Az'
84+
Install-ModuleFast 'ImportExcel','VMware.PowerCLI.Sdk=12.6.0.19600125','PowerConfig<0.1.6','Az.Compute:7.1.*' -WhatIf
85+
86+
Prepares an install plan for the latest version of ImportExcel, a specific version of VMware.PowerCLI.Sdk, a version of PowerConfig less than 0.1.6, and the latest version of Az.Compute that is in the 7.1.x range.
87+
88+
--- RESULT ---
89+
Name ModuleVersion
90+
---- -------------
91+
VMware.PowerCLI.Sdk 12.6.0.19600125
92+
ImportExcel 7.8.6
93+
PowerConfig 0.1.5
94+
Az.Compute 7.1.0
95+
VMware.PowerCLI.Sdk.Types 12.6.0.19600125
96+
Az.Accounts 2.13.2
97+
4398
.EXAMPLE
44-
$plan = Get-ModuleFastPlan 'Az','VMWare.PowerCLI'
99+
$plan = Install-ModuleFast 'ImportExcel' -WhatIf
45100
$plan | Install-ModuleFast
101+
102+
Stores an Install Plan for ImportExcel in the $plan variable, then installs it. The later install can be done later, and the $plan objects are serializable to CLIXML/JSON/etc. for storage.
103+
104+
--- RESULT ---
105+
What if: Performing the operation "Install 1 Modules" on target "C:\Users\JGrote\AppData\Local\powershell\Modules". Name ModuleVersion
106+
---- -------------
107+
ImportExcel 7.8.6
108+
46109
.EXAMPLE
47-
$plan = Install-ModuleFast 'Az','VMWare.PowerCLI' -WhatIf
48-
$plan | Install-ModuleFast
110+
@{ModuleName='ImportExcel';ModuleVersion='7.8.6'} | Install-ModuleFast
111+
112+
Installs a specific version of ImportExcel using
113+
114+
.EXAMPLE
115+
Install-ModuleFast 'ImportExcel' -Destination 'CurrentUser' -NoProfileUpdate -NoPSModulePathUpdate
116+
117+
Installs ImportExcel to the legacy PowerShell Modules folder in My Documents on Windows only, but does not update the PSModulePath or the user profile to include the new module path. This behavior is similar to Install-Module or Install-PSResource.
118+
119+
.EXAMPLE
120+
Install-ModuleFast -Path 'path\to\RequiresScript.ps1' -WhatIf
121+
122+
Prepares a plan to install the dependencies defined in the #Requires statement of a script if a .ps1 is specified, the #Requires statement of a module if .psm1 is specified, or the RequiredModules section of a .psd1 file if it is a PowerShell Module Manifest. This is useful for quickly installing dependencies for scripts or modules.
123+
124+
RequiresScript.ps1 Contents:
125+
#Requires -Module PreReleaseTest
126+
127+
--- RESULT ---
128+
129+
What if: Performing the operation "Install 1 Modules" on target "C:\Users\JGrote\AppData\Local\powershell\Modules".
130+
131+
Name ModuleVersion
132+
---- -------------
133+
PrereleaseTest 0.0.1
134+
135+
.EXAMPLE
136+
Install-ModuleFast -WhatIf
137+
138+
If no Specification or Path parameter is provided, ModuleFast will search for a .requires.json or a .requires.psd1 file in the current directory and install the modules specified in that file. This is useful for quickly installing dependencies for scripts or modules during a CI build or Github Action.
139+
140+
Note that for this format you can explicitly specify 'latest' or ':*' as the version to install the latest version of a module.
141+
142+
Module.requires.psd1 Contents:
143+
@{
144+
ImportExcel = 'latest'
145+
}
146+
147+
--- Result ---
148+
149+
49150
#>
50151

51152
[CmdletBinding(SupportsShouldProcess, DefaultParameterSetName = 'Specification')]

0 commit comments

Comments
 (0)