Copying InstallModule.ps1 from tools folder, main branch (#16589)
This commit is contained in:
Родитель
e6fed17016
Коммит
118decb4d0
|
@ -0,0 +1,39 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
.
|
||||
.DESCRIPTION
|
||||
.
|
||||
.PARAMETER ModuleName
|
||||
Name of the module to install. By default all modules are installed.
|
||||
.PARAMETER SourceLocation
|
||||
Specifies the path for discovering and installing modules from.
|
||||
Taking current folder as source location by default
|
||||
.EXAMPLE
|
||||
C:\PS> ./InstallModule.ps1 -ModuleName Az.Accounts
|
||||
.NOTES
|
||||
Author: Beisi Zhou
|
||||
Date: July 21, 2021
|
||||
#>
|
||||
|
||||
[cmdletbinding()]
|
||||
param(
|
||||
[string]
|
||||
[Parameter(Mandatory = $false, Position = 0, HelpMessage = "Name of the module to install. By default all modules are installed.")]
|
||||
$ModuleName = "Az",
|
||||
[string]
|
||||
[Parameter(Mandatory = $false, Position = 1, HelpMessage = "Specifies the path for discovering and installing modules from.")]
|
||||
$SourceLocation = $PSScriptRoot
|
||||
)
|
||||
|
||||
$gallery = [guid]::NewGuid().ToString()
|
||||
Write-Host "Registering temporary repository $gallery with InstallationPolicy Trusted..."
|
||||
Register-PSRepository -Name $gallery -SourceLocation $SourceLocation -PackageManagementProvider NuGet -InstallationPolicy Trusted
|
||||
|
||||
try {
|
||||
Write-Host "Installing $ModuleName..."
|
||||
Install-Module -Name $ModuleName -Repository $gallery -Scope CurrentUser -AllowClobber -Force
|
||||
}
|
||||
finally {
|
||||
Write-Host "Unregistering gallery $gallery..."
|
||||
Unregister-PSRepository -Name $gallery
|
||||
}
|
Загрузка…
Ссылка в новой задаче