diff --git a/testTaskGate.ps1 b/testTaskGate.ps1
index 3aae319..a76fc1f 100644
--- a/testTaskGate.ps1
+++ b/testTaskGate.ps1
@@ -1,10 +1,10 @@
### To Modify as of January 27 2025
### let's start thinking about the write-log -TaskCategory "On-boarding" or "Off-boarding"
-### need RGB color codes form john, once we picked the RGBA colors
-### add the .net silent install tweaks to toolkit
+### need RGB color codes from john, once we picked the RGBA colors
+### add the .NET silent install tweaks to toolkit
### for the reg tweak need to do/undo function maybe it should have its own check box list
-### added offboard check boxes for dattormm, dattodeb, rocketcyber, cyberQP, SVSHelpdesk and Splashtop
+### added offboard check boxes for DattoRMM, DattoDEB, RocketCyber, CyberQP, SVSHelpdesk and Splashtop
### need to fix path in the uninstall-DattoEDR -
####### ❌ [Error] [GeneralTask] Uninstallation command 'C:\Program Files\Infocyte\Agent\agent.exe' not found. (Event ID: 3000) - bad path
@@ -42,13 +42,6 @@ if (-not (Get-Command -Name Write-Log -CommandType Function -ErrorAction Silentl
"Success" { ([char]0x2705) }
"General" { ([char]0x1F4E6) }
}
- $Color = switch ($Level) {
- "Info" { "Cyan" }
- "Warning" { "Yellow" }
- "Error" { "Red" }
- "Success" { "Green" }
- "General" { "White" }
- }
$logEntry = [PSCustomObject]@{
Timestamp = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss")
Level = $Level
@@ -70,7 +63,7 @@ if (-not (Get-Command -Name Write-Log -CommandType Function -ErrorAction Silentl
Write-EventLog -LogName $EventLog -Source $EventSource -EntryType $EntryType -EventId $EventID -Message $EventMessage
}
catch {
- Write-Host "([char]0x26A0) [Warning] [EventLog] Failed to write to Event Log: $($_.Exception.Message)" -ForegroundColor Yellow
+ Write-Host "⚠ [Warning] [EventLog] Failed to write to Event Log: $($_.Exception.Message)" -ForegroundColor Yellow
}
}
}
@@ -128,11 +121,11 @@ function Install-DattoRMM-Helper {
Write-LogHybrid -Message "Fetching OAuth token..." -Level "Info"
try {
$securePassword = ConvertTo-SecureString -String 'public' -AsPlainText -Force
- $apiGenToken = Invoke-WebRequest -Credential (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList ('public-client', $securePassword)) `
- -Uri ('{0}/auth/oauth/token' -f $ApiUrl) `
+ $apiGenToken = Invoke-WebRequest -Credential (New-Object System.Management.Automation.PSCredential -ArgumentList ('public-client', $securePassword)) `
+ -Uri ("{0}/auth/oauth/token" -f $ApiUrl) `
-Method 'POST' `
-ContentType 'application/x-www-form-urlencoded' `
- -Body ('grant_type=password&username={0}&password={1}' -f $ApiKey, $ApiSecretKey) `
+ -Body ("grant_type=password&username={0}&password={1}" -f $ApiKey, $ApiSecretKey) `
| ConvertFrom-Json
$requestToken = $apiGenToken.access_token
Write-LogHybrid -Message "OAuth token fetched successfully." -Level "Success" -LogToEvent
@@ -140,23 +133,19 @@ function Install-DattoRMM-Helper {
Write-LogHybrid -Message "Failed to fetch OAuth token. Details: $($_.Exception.Message)" -Level "Error" -LogToEvent
return
}
- $getHeaders = @{"Authorization" = "Bearer $requestToken"}
if ($FetchSitesOnly) {
Write-Host "Fetching list of sites from the Datto RMM API..." -ForegroundColor Cyan
try {
- $getSites = Invoke-WebRequest -Uri "$ApiUrl/api/v2/account/sites" -Method Get -Headers $getHeaders -ContentType "application/json"
+ $getSites = Invoke-WebRequest -Uri "$ApiUrl/api/v2/account/sites" -Method Get -Headers @{ "Authorization" = "Bearer $requestToken" } -ContentType "application/json"
$sitesJson = $getSites.Content | ConvertFrom-Json
$siteList = $sitesJson.sites | ForEach-Object {
- [PSCustomObject]@{
- Name = $_.name
- UID = $_.uid
- }
+ [PSCustomObject]@{ Name = $_.name; UID = $_.uid }
}
Write-Host "Successfully fetched list of sites." -ForegroundColor Green
return $siteList
}
catch {
- Write-Host "Failed to fetch sites from the API. Details: $($_.Exception.Message)" -ForegroundColor Red
+ Write-Host "Failed to fetch sites: $($_.Exception.Message)" -ForegroundColor Red
return
}
}
@@ -165,46 +154,34 @@ function Install-DattoRMM-Helper {
#region LastPass Extensions
function ForceInstall-LastPassChrome {
- # Chrome (Web Store) extension ID and update URL for LastPass
- $ExtensionID_LastPass_Chrome = "hdokiejnpimakedhajhdlcegeplioahd"
- $ChromeUpdateURL = "https://clients2.google.com/service/update2/crx"
- $ChromePolicyRegPath = "HKLM:\SOFTWARE\Policies\Google\Chrome\ExtensionInstallForcelist"
+ $ExtensionID = "hdokiejnpimakedhajhdlcegeplioahd"
+ $UpdateURL = "https://clients2.google.com/service/update2/crx"
+ $RegPath = "HKLM:\SOFTWARE\Policies\Google\Chrome\ExtensionInstallForcelist"
try {
- New-Item -Path "HKLM:\SOFTWARE\Policies\Google" -Force -ErrorAction SilentlyContinue | Out-Null
- New-Item -Path "HKLM:\SOFTWARE\Policies\Google\Chrome" -Force -ErrorAction SilentlyContinue | Out-Null
- New-Item -Path $ChromePolicyRegPath -Force -ErrorAction SilentlyContinue | Out-Null
- $chromeValue = "$ExtensionID_LastPass_Chrome;$ChromeUpdateURL"
- Set-ItemProperty -Path $ChromePolicyRegPath -Name "1" -Value $chromeValue -ErrorAction Stop
- Write-Host "Successfully configured LastPass in Chrome ExtensionInstallForcelist."
+ New-Item -Path (Split-Path $RegPath) -Force -ErrorAction SilentlyContinue | Out-Null
+ New-Item -Path $RegPath -Force -ErrorAction SilentlyContinue | Out-Null
+ Set-ItemProperty -Path $RegPath -Name "1" -Value "$ExtensionID;$UpdateURL" -ErrorAction Stop
+ Write-Host "Configured LastPass Chrome extension."
}
catch {
- Write-Host "Failed to configure Chrome: $($_.Exception.Message)" -ForegroundColor Red
+ Write-Host "Failed Chrome config: $($_.Exception.Message)" -ForegroundColor Red
}
}
-
function ForceInstall-LastPassEdge {
- # Edge (Add-ons Store) extension ID and update URL for LastPass
- $ExtensionID_LastPass_Edge = "bbcinlkgjjkejfdpemiealijmmooekmp"
- $EdgeUpdateURL = "https://edge.microsoft.com/extensionwebstorebase/v1/crx"
- $EdgePolicyRegPath = "HKLM:\SOFTWARE\Policies\Microsoft\Edge\ExtensionInstallForcelist"
+ $ExtensionID = "bbcinlkgjjkejfdpemiealijmmooekmp"
+ $UpdateURL = "https://edge.microsoft.com/extensionwebstorebase/v1/crx"
+ $RegPath = "HKLM:\SOFTWARE\Policies\Microsoft\Edge\ExtensionInstallForcelist"
try {
- New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft" -Force -ErrorAction SilentlyContinue | Out-Null
- New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Edge" -Force -ErrorAction SilentlyContinue | Out-Null
- New-Item -Path $EdgePolicyRegPath -Force -ErrorAction SilentlyContinue | Out-Null
- $edgeValue = "$ExtensionID_LastPass_Edge;$EdgeUpdateURL"
- Set-ItemProperty -Path $EdgePolicyRegPath -Name "1" -Value $edgeValue -ErrorAction Stop
- Write-Host "Successfully configured LastPass in Edge ExtensionInstallForcelist."
+ New-Item -Path (Split-Path $RegPath) -Force -ErrorAction SilentlyContinue | Out-Null
+ New-Item -Path $RegPath -Force -ErrorAction SilentlyContinue | Out-Null
+ Set-ItemProperty -Path $RegPath -Name "1" -Value "$ExtensionID;$UpdateURL" -ErrorAction Stop
+ Write-Host "Configured LastPass Edge extension."
}
catch {
- Write-Host "Failed to configure Edge: $($_.Exception.Message)" -ForegroundColor Red
+ Write-Host "Failed Edge config: $($_.Exception.Message)" -ForegroundColor Red
}
}
-
-function Install-LastPassExtensions {
- param(
- [switch]$Chrome,
- [switch]$Edge
- )
+function Install-LastPassExtensions { param([switch]$Chrome,[switch]$Edge)
if ($Chrome) { ForceInstall-LastPassChrome }
if ($Edge) { ForceInstall-LastPassEdge }
}
@@ -215,167 +192,80 @@ function Install-SVSMSP {
param (
[switch]$Cleanup,
[switch]$InstallToolkit,
- [Parameter(Mandatory = $false)]
- [array]$AllModules = @(
- @{ ModuleName = "SVS_Toolkit" },
- @{ ModuleName = "SVSMSP" }
- ),
- [Parameter(Mandatory = $false)]
- [string]$NewModuleName = "SVSMSP",
- [Parameter(Mandatory = $false)]
- [array]$AllRepositories = @(
- @{ RepoName = "SVS_Repo" },
- @{ RepoName = "SVS_Toolkit" }
- ),
- [Parameter(Mandatory = $false)]
+ [array]$AllModules = @(@{ModuleName="SVS_Toolkit"},@{ModuleName="SVSMSP"}),
+ [string]$NewModuleName = "SVSMSP",
+ [array]$AllRepositories = @(@{RepoName="SVS_Repo"},@{RepoName="SVS_Toolkit"}),
[string]$NewRepositoryName = "SVS_Repo",
- [Parameter(Mandatory = $false)]
- [string]$NewRepositoryURL = "http://proget.svstools.ca:8083/nuget/SVS_Repo/",
- [Parameter(Mandatory = $false)]
- [array]$CommandsToCheck = @(
- "Install-DattoRMM",
- "Install-CyberQP",
- "Install-RocketCyber",
- "Install-Splashtop",
- "Install-ThreatLocker",
- "Install-SVSHelpdesk"
- ),
- [Parameter(Mandatory = $false)]
- [string]$LogFilePath = "$env:SVSMSP\svstoolkit.log"
+ [string]$NewRepositoryURL = "http://proget.svstools.ca:8083/nuget/SVS_Repo/",
+ [string]$LogFilePath = "$env:SVSMSP\svstoolkit.log"
)
function Perform-Cleanup {
- Write-LogHybrid -Message "Cleanup mode enabled. Starting cleanup process..." -Level "Info" -LogToEvent
- Write-LogHybrid -Message "Starting cleanup of old modules..." -Level "Info" -LogToEvent
- foreach ($module in $AllModules) {
- $ModuleName = $module.ModuleName
- if (Get-Module -Name $ModuleName -ListAvailable) {
- Write-LogHybrid -Message "Removing module '$ModuleName'..." -Level "Warning" -LogToEvent
- try {
- Get-Module -Name $ModuleName -ListAvailable | ForEach-Object {
- Uninstall-Module -Name $_.Name -AllVersions -Force
- }
- Write-LogHybrid -Message "Module '$ModuleName' removed successfully." -Level "Success" -LogToEvent
- }
- catch {
- Write-LogHybrid -Message "Failed to remove module '$ModuleName'. Error: $($_.Exception.Message)" -Level "Error" -LogToEvent
- }
- }
- else {
- Write-LogHybrid -Message "Module '$ModuleName' not found. Skipping..." -Level "Info" -LogToEvent
+ Write-LogHybrid -Message "Cleanup mode enabled..." -Level Info -LogToEvent
+ foreach ($m in $AllModules) {
+ if (Get-Module -Name $m.ModuleName -ListAvailable) {
+ Write-LogHybrid -Message "Removing $($m.ModuleName)..." -Level Warning -LogToEvent
+ try { Uninstall-Module -Name $m.ModuleName -AllVersions -Force; Write-LogHybrid -Message "Removed $($m.ModuleName)" -Level Success -LogToEvent }
+ catch { Write-LogHybrid -Message "Failed to remove $($m.ModuleName): $_" -Level Error -LogToEvent }
}
}
- Write-LogHybrid -Message "Starting cleanup of old repositories..." -Level "Info" -LogToEvent
- foreach ($repo in $AllRepositories) {
- $RepoName = $repo.RepoName
- Write-LogHybrid -Message "Removing repository '$RepoName'..." -Level "Warning" -LogToEvent
- if (Get-PSRepository -Name $RepoName -ErrorAction SilentlyContinue) {
- try {
- Unregister-PSRepository -Name $RepoName -ErrorAction Stop
- Write-LogHybrid -Message "Repository '$RepoName' removed successfully." -Level "Success" -LogToEvent
- }
- catch {
- Write-LogHybrid -Message "Failed to remove repository '$RepoName'. Error: $($_.Exception.Message)" -Level "Error" -LogToEvent
- }
- }
- else {
- Write-LogHybrid -Message "Repository '$RepoName' does not exist. Skipping removal." -Level "Info" -LogToEvent
+ foreach ($r in $AllRepositories) {
+ if (Get-PSRepository -Name $r.RepoName -ErrorAction SilentlyContinue) {
+ Write-LogHybrid -Message "Unregistering $($r.RepoName)..." -Level Warning -LogToEvent
+ try { Unregister-PSRepository -Name $r.RepoName -ErrorAction Stop; Write-LogHybrid -Message "Unregistered $($r.RepoName)" -Level Success -LogToEvent }
+ catch { Write-LogHybrid -Message "Failed to unregister $($r.RepoName): $_" -Level Error -LogToEvent }
}
}
- Write-LogHybrid -Message "Cleanup process completed successfully." -Level "Success" -LogToEvent
+ Write-LogHybrid -Message "Cleanup complete." -Level Success -LogToEvent
}
function Perform-ToolkitInstallation {
Perform-Cleanup
- $localMachineExecutionPolicy = Get-ExecutionPolicy -Scope LocalMachine
- if ($localMachineExecutionPolicy -ne "RemoteSigned") {
- Write-LogHybrid -Message "Setting execution policy to RemoteSigned..." -Level "Warning" -LogToEvent
- try {
- Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine -Force
- Write-LogHybrid -Message "Execution policy set to RemoteSigned successfully." -Level "Success" -LogToEvent
- }
- catch {
- Write-LogHybrid -Message "Failed to set execution policy. Error: $_" -Level "Error" -LogToEvent
- return
- }
+ if ((Get-ExecutionPolicy -Scope LocalMachine) -ne "RemoteSigned") {
+ Write-LogHybrid -Message "Setting execution policy to RemoteSigned..." -Level Warning -LogToEvent
+ try { Set-ExecutionPolicy RemoteSigned -Scope LocalMachine -Force; Write-LogHybrid -Message "Policy set." -Level Success -LogToEvent }
+ catch { Write-LogHybrid -Message "Failed to set policy: $_" -Level Error -LogToEvent; return }
}
- Install-PackageProvider -Name "NuGet" -Force -Scope AllUsers -Confirm:$false
- Write-LogHybrid -Message "Registering the new repository '$NewRepositoryName'..." -Level "Info" -LogToEvent
- try {
- if (!(Get-PSRepository -Name $NewRepositoryName -ErrorAction SilentlyContinue)) {
- Register-PSRepository -Name $NewRepositoryName -SourceLocation $NewRepositoryURL -InstallationPolicy Trusted
- Write-LogHybrid -Message "Repository '$NewRepositoryName' registered successfully." -Level "Success" -LogToEvent
- }
+ Install-PackageProvider -Name NuGet -Force -Scope AllUsers -Confirm:$false
+ if (-not (Get-PSRepository -Name $NewRepositoryName -ErrorAction SilentlyContinue)) {
+ Write-LogHybrid -Message "Registering $NewRepositoryName..." -Level Info -LogToEvent
+ try { Register-PSRepository -Name $NewRepositoryName -SourceLocation $NewRepositoryURL -InstallationPolicy Trusted; Write-LogHybrid -Message "Registered." -Level Success -LogToEvent }
+ catch { Write-LogHybrid -Message "Register failed: $_" -Level Error -LogToEvent }
}
- catch {
- Write-LogHybrid -Message "Failed to register new repository '$NewRepositoryName'. Error: $($_.Exception.Message)" -Level "Error" -LogToEvent
- }
- Write-LogHybrid -Message "Installing the new module '$NewModuleName'..." -Level "Info" -LogToEvent
- try {
- Install-Module -Name $NewModuleName -Repository $NewRepositoryName -Scope AllUsers -Force
- Write-LogHybrid -Message "Module '$NewModuleName' installed successfully." -Level "Success" -LogToEvent
- }
- catch {
- Write-LogHybrid -Message "Failed to install new module '$NewModuleName'. Error: $($_.Exception.Message)" -Level "Error" -LogToEvent
- }
- Write-LogHybrid -Message "Toolkit installation process completed successfully." -Level "Success" -LogToEvent
+ Write-LogHybrid -Message "Installing $NewModuleName..." -Level Info -LogToEvent
+ try { Install-Module -Name $NewModuleName -Repository $NewRepositoryName -Scope AllUsers -Force; Write-LogHybrid -Message "Installed." -Level Success -LogToEvent }
+ catch { Write-LogHybrid -Message "Install failed: $_" -Level Error -LogToEvent }
}
- Write-LogHybrid -Message "Install-SVSMSP function started." -Level "Info" -LogToEvent
- if ($Cleanup) {
- Perform-Cleanup
- return
- }
- if ($InstallToolkit) {
- Perform-ToolkitInstallation
- return
- }
- Write-LogHybrid -Message "No specific mode specified. Defaulting to toolkit installation mode..." -Level "Info" -LogToEvent
+ Write-LogHybrid -Message "Install-SVSMSP started." -Level Info -LogToEvent
+ if ($Cleanup) { Perform-Cleanup; return }
+ if ($InstallToolkit) { Perform-ToolkitInstallation; return }
Perform-ToolkitInstallation
}
-#endregion SVS Module
+#endregion
#region HTTP Listener Setup
try {
$listener = New-Object System.Net.HttpListener
- if (-not $listener) {
- throw "Failed to initialize HttpListener."
- }
$listener.Prefixes.Add("http://localhost:8081/")
- Write-LogHybrid -Message "Listener initialized with prefix http://localhost:8081/" -Level "Info"
+ Write-LogHybrid -Message "Listener prefix added." -Level Info
$listener.Start()
- Write-LogHybrid -Message "Listener started successfully." -Level "Info"
+ Write-LogHybrid -Message "Listener started." -Level Info
} catch {
- Write-LogHybrid -Message "Critical error initializing listener: $($_.Exception.Message)" -Level "Error"
- throw $_
+ Write-LogHybrid -Message "Listener init error: $($_.Exception.Message)" -Level Error
+ throw
}
#endregion
function Get-N8nWebhookData {
- param (
- [Parameter(Mandatory = $true)]
- [string]$AuthHeaderValue
- )
- $url = "https://automate.svstools.ca/webhook/svsmspkit"
- $headers = @{
- "SVSMSPKit" = $AuthHeaderValue
- }
+ param ([string]$AuthHeaderValue)
+ $url = "https://automate.svstools.ca/webhook/svsmspkit"
+ $headers = @{ "SVSMSPKit" = $AuthHeaderValue }
try {
- $response = Invoke-RestMethod -Uri $url -Headers $headers -Method Get
- Write-Host "Response received successfully:" -ForegroundColor Green
- $data = $response
- $global:Comment_SVSmodule = $data._Comment_SVSmodule
- $global:ModuleName = $data.ModuleName
- $global:RepositoryURL = $data.RepositoryURL
- $global:OldRepo = $data.OldRepo
- $global:NewRepo = $data.NewRepo
- $global:CommandsToCheck = $data.CommandsToCheck
- $global:LogFilePath = $data.LogFilePath
- $global:Comment_DRMM = $data._Comment_DRMM
- $global:ApiUrl = $data.ApiUrl
- $global:ApiKey = $data.ApiKey
- $global:ApiSecretKey = $data.ApiSecretKey
- }
- catch {
- Write-Host "Error making the GET request:" -ForegroundColor Red
- Write-Host $_.Exception.Message
+ $resp = Invoke-RestMethod -Uri $url -Headers $headers -Method Get
+ foreach ($prop in $resp.PSObject.Properties) {
+ Set-Variable -Name $prop.Name -Value $prop.Value -Scope Global
+ }
+ return $resp
+ } catch {
+ Write-Host "Webhook GET error: $($_.Exception.Message)" -ForegroundColor Red
return $null
}
}
@@ -386,271 +276,292 @@ function GetHtmlContent {
-
-
- SVS TaskGate
-
-
+
+ SVS TaskGate
+
+
-
-

+
+

+
+