From aea67d4727fc97d088ca86ecb7f5c715a944c2be Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Tue, 28 Jan 2025 00:54:51 -0500 Subject: [PATCH] Update TGBeta.ps1 --- TGBeta.ps1 | 60 +++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/TGBeta.ps1 b/TGBeta.ps1 index b378e72..72e4e26 100644 --- a/TGBeta.ps1 +++ b/TGBeta.ps1 @@ -222,12 +222,22 @@ function Install-DattoRMM-Helper { #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 { param ( - # Cleanup flag + # Cleanup flag: Removes old modules and repositories if enabled. [switch]$Cleanup, - # Toolkit installation flag + # Toolkit installation flag: Installs required modules and repositories. [switch]$InstallToolkit, # Module settings @@ -265,21 +275,15 @@ function Install-SVSMSP { ), - # Log file path + # Log file path for tracking installation steps [Parameter(Mandatory = $false)] [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 { 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 } + ### Function: Perform-ToolkitInstallation + # - Handles the installation of new repositories and modules. + # - Ensures execution policies are correctly set. function Perform-ToolkitInstallation { - # Perform cleanup + + # Step 1: Cleanup old modules and repositories Perform-Cleanup - # Step 1: Set Execution Policy + # Step 2: Set Execution Policy $localMachineExecutionPolicy = Get-ExecutionPolicy -Scope LocalMachine if ($localMachineExecutionPolicy -ne "RemoteSigned") { Write-LogHybrid -Message "Setting execution policy to RemoteSigned..." -Level "Warning" -LogToEvent @@ -344,20 +352,10 @@ function Install-SVSMSP { } } - # Step 2: Ensure NuGet is Installed - #if (!(Get-PackageProvider -Name "NuGet" -ErrorAction SilentlyContinue)) { - # Write-LogHybrid -Message "NuGet package provider not found. Installing..." -Level "Warning" -LogToEvent - # try { - 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 + # Step 3: Ensure NuGet is Installed + Install-PackageProvider -Name "NuGet" -Force -Scope AllUsers -Confirm:$false + + # Step 4: Register the new repository Write-LogHybrid -Message "Registering the new repository '$NewRepositoryName'..." -Level "Info" -LogToEvent try { 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 } - # Step 4: Install the new module + # Step 5: Install the new module Write-LogHybrid -Message "Installing the new module '$NewModuleName'..." -Level "Info" -LogToEvent try { 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 } + ### 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 if ($Cleanup) {