Update TGBeta.ps1

This commit is contained in:
2025-01-28 00:54:51 -05:00
parent 3468cf0991
commit aea67d4727

View File

@@ -222,12 +222,22 @@ function Install-DattoRMM-Helper {
#region SVS Module #region SVS Module
### SVS Module Overview:
# - This section includes the Install-SVSMSP function, which handles:
# 1. Cleanup of old modules and repositories.
# 2. Installation of new modules and repositories.
# 3. Setting execution policies and prerequisites.
# - TODO:
# 1. Validate all parameters for completeness and add error messages for missing inputs.
# 2. Refactor cleanup and installation steps for modularity and reusability.
function Install-SVSMSP { function Install-SVSMSP {
param ( param (
# Cleanup flag # Cleanup flag: Removes old modules and repositories if enabled.
[switch]$Cleanup, [switch]$Cleanup,
# Toolkit installation flag # Toolkit installation flag: Installs required modules and repositories.
[switch]$InstallToolkit, [switch]$InstallToolkit,
# Module settings # Module settings
@@ -265,21 +275,15 @@ function Install-SVSMSP {
), ),
# Log file path # Log file path for tracking installation steps
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
[string]$LogFilePath = "$env:SVSMSP\svstoolkit.log", [string]$LogFilePath = "$env:SVSMSP\svstoolkit.log",
# DRMM API Settings
[Parameter(Mandatory = $false)]
[string]$ApiUrl,
[Parameter(Mandatory = $false)]
[string]$ApiKey,
[Parameter(Mandatory = $false)]
[string]$ApiSecretKey
) )
### Function: Perform-Cleanup
# - Removes all old modules and repositories.
# - Logs each step for debugging purposes.
function Perform-Cleanup { function Perform-Cleanup {
Write-LogHybrid -Message "Cleanup mode enabled. Starting cleanup process..." -Level "Info" -LogToEvent Write-LogHybrid -Message "Cleanup mode enabled. Starting cleanup process..." -Level "Info" -LogToEvent
@@ -326,11 +330,15 @@ function Install-SVSMSP {
Write-LogHybrid -Message "Cleanup process completed successfully." -Level "Success" -LogToEvent Write-LogHybrid -Message "Cleanup process completed successfully." -Level "Success" -LogToEvent
} }
### Function: Perform-ToolkitInstallation
# - Handles the installation of new repositories and modules.
# - Ensures execution policies are correctly set.
function Perform-ToolkitInstallation { function Perform-ToolkitInstallation {
# Perform cleanup
# Step 1: Cleanup old modules and repositories
Perform-Cleanup Perform-Cleanup
# Step 1: Set Execution Policy # Step 2: Set Execution Policy
$localMachineExecutionPolicy = Get-ExecutionPolicy -Scope LocalMachine $localMachineExecutionPolicy = Get-ExecutionPolicy -Scope LocalMachine
if ($localMachineExecutionPolicy -ne "RemoteSigned") { if ($localMachineExecutionPolicy -ne "RemoteSigned") {
Write-LogHybrid -Message "Setting execution policy to RemoteSigned..." -Level "Warning" -LogToEvent Write-LogHybrid -Message "Setting execution policy to RemoteSigned..." -Level "Warning" -LogToEvent
@@ -344,20 +352,10 @@ function Install-SVSMSP {
} }
} }
# Step 2: Ensure NuGet is Installed # Step 3: Ensure NuGet is Installed
#if (!(Get-PackageProvider -Name "NuGet" -ErrorAction SilentlyContinue)) { Install-PackageProvider -Name "NuGet" -Force -Scope AllUsers -Confirm:$false
# Write-LogHybrid -Message "NuGet package provider not found. Installing..." -Level "Warning" -LogToEvent
# try { # Step 4: Register the new repository
Install-PackageProvider -Name "NuGet" -Force -Scope AllUsers -Confirm:$false
# Write-LogHybrid -Message "NuGet package provider installed successfully." -Level "Success" -LogToEvent
# }
# catch {
# Write-LogHybrid -Message "Failed to install NuGet package provider. Error: $_" -Level "Error" -LogToEvent
# return
# }
#}
# Step 3: Register the new repository
Write-LogHybrid -Message "Registering the new repository '$NewRepositoryName'..." -Level "Info" -LogToEvent Write-LogHybrid -Message "Registering the new repository '$NewRepositoryName'..." -Level "Info" -LogToEvent
try { try {
if (!(Get-PSRepository -Name $NewRepositoryName -ErrorAction SilentlyContinue)) { if (!(Get-PSRepository -Name $NewRepositoryName -ErrorAction SilentlyContinue)) {
@@ -369,7 +367,7 @@ function Install-SVSMSP {
Write-LogHybrid -Message "Failed to register new repository '$NewRepositoryName'. Error: $($_.Exception.Message)" -Level "Error" -LogToEvent Write-LogHybrid -Message "Failed to register new repository '$NewRepositoryName'. Error: $($_.Exception.Message)" -Level "Error" -LogToEvent
} }
# Step 4: Install the new module # Step 5: Install the new module
Write-LogHybrid -Message "Installing the new module '$NewModuleName'..." -Level "Info" -LogToEvent Write-LogHybrid -Message "Installing the new module '$NewModuleName'..." -Level "Info" -LogToEvent
try { try {
Install-Module -Name $NewModuleName -Repository $NewRepositoryName -Scope AllUsers -Force Install-Module -Name $NewModuleName -Repository $NewRepositoryName -Scope AllUsers -Force
@@ -382,6 +380,8 @@ function Install-SVSMSP {
Write-LogHybrid -Message "Toolkit installation process completed successfully." -Level "Success" -LogToEvent Write-LogHybrid -Message "Toolkit installation process completed successfully." -Level "Success" -LogToEvent
} }
### Function Execution Logic
# - Determines whether to run cleanup, toolkit installation, or default to toolkit installation mode.
Write-LogHybrid -Message "Install-SVSMSP function started." -Level "Info" -LogToEvent Write-LogHybrid -Message "Install-SVSMSP function started." -Level "Info" -LogToEvent
if ($Cleanup) { if ($Cleanup) {