Add scripts for installing PS modules

This commit is contained in:
Manuel Thalmann 2024-08-07 22:55:25 +02:00
parent dd902e4859
commit 5e2e43735e
4 changed files with 87 additions and 0 deletions
scripts/Common/Software/PowerShell

View file

@ -0,0 +1,54 @@
. "$PSScriptRoot/../../Types/InstallerAction.ps1";
$null = New-Module {
. "$PSScriptRoot/../../Software/PowerShell/Profile.ps1";
<#
.SYNOPSIS
Generates the components for creating a module installer.
.PARAMETER Name
The name of the module to install.
#>
function Get-ModuleInstallerComponents {
param(
[string] $Name
)
@{
arguments = @{
name = $Name;
};
installer = {
param(
[scriptblock] $Installer,
[hashtable] $Arguments
)
$env:PENDING_MODULE_NAME = $Arguments.Name;
$installAction = { Install-Module -Scope AllUsers -Force $env:PENDING_MODULE_NAME @args };
& $installAction -AcceptLicense;
if (Test-Command powershell) {
powershell -c ($installAction.ToString());
}
Remove-Item Env:\PENDING_MODULE_NAME;
& $Installer -Action ([InstallerAction]::Configure) @PSBoundParameters;
};
configurator = {
param(
[hashtable] $Arguments
)
$name = $Arguments.Name;
Add-PowerShellProfileStatement `
-DefaultUser `
-Category $name `
-Script "Import-Module `"$name`";";
};
}
}
};