Skip to content

Commit 7f81eb1

Browse files
Add script to install module (#15497)
* Add script to install module * refine codes * Update tools/InstallModule.ps1 Co-authored-by: Yeming Liu <[email protected]> * move script to installer * replace tab with space * fix * add comment-based synopsis Co-authored-by: Yeming Liu <[email protected]>
1 parent 1c9b5c6 commit 7f81eb1

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tools/Installer/InstallModule.ps1

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<#
2+
.SYNOPSIS
3+
.
4+
.DESCRIPTION
5+
.
6+
.PARAMETER ModuleName
7+
Name of the module to install. By default all modules are installed.
8+
.PARAMETER SourceLocation
9+
Specifies the path for discovering and installing modules from.
10+
Taking current folder as source location by default
11+
.EXAMPLE
12+
C:\PS> ./InstallModule.ps1 -ModuleName Az.Accounts
13+
.NOTES
14+
Author: Beisi Zhou
15+
Date: July 21, 2021
16+
#>
17+
18+
[cmdletbinding()]
19+
param(
20+
[string]
21+
[Parameter(Mandatory = $false, Position = 0, HelpMessage = "Name of the module to install. By default all modules are installed.")]
22+
$ModuleName = "Az",
23+
[string]
24+
[Parameter(Mandatory = $false, Position = 1, HelpMessage = "Specifies the path for discovering and installing modules from.")]
25+
$SourceLocation = $PSScriptRoot
26+
)
27+
28+
$gallery = [guid]::NewGuid().ToString()
29+
Write-Host "Registering temporary repository $gallery with InstallationPolicy Trusted..."
30+
Register-PSRepository -Name $gallery -SourceLocation $SourceLocation -PackageManagementProvider NuGet -InstallationPolicy Trusted
31+
32+
try {
33+
Write-Host "Installing $ModuleName..."
34+
Install-Module -Name $ModuleName -Repository $gallery -Scope CurrentUser -AllowClobber -Force
35+
}
36+
finally {
37+
Write-Host "Unregistering gallery $gallery..."
38+
Unregister-PSRepository -Name $gallery
39+
}

0 commit comments

Comments
 (0)