Copying InstallModule.ps1 from tools folder, main branch (#16589)

This commit is contained in:
bganapa 2021-12-06 19:01:39 -08:00 коммит произвёл GitHub
Родитель e6fed17016
Коммит 118decb4d0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 39 добавлений и 0 удалений

Просмотреть файл

@ -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
}