Skip to content

Commit adcbc33

Browse files
Merge pull request #270 from P6g9YHK6/main
updates
2 parents d446b64 + 77f383c commit adcbc33

File tree

3 files changed

+191
-3
lines changed

3 files changed

+191
-3
lines changed

scripts_staging/Checks/Active Directory Health.ps1

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@ function Compare-GPOVersions {
9090
}
9191
}
9292

93+
# Function to check if the Recycle Bin in enabled
94+
95+
function Check-ADRecycleBin {
96+
$recycleFeatures = Get-ADOptionalFeature -Filter {name -like "recycle bin feature"}
97+
98+
foreach ($feature in $recycleFeatures) {
99+
if ($null -ne $feature.EnabledScopes) {
100+
Write-Output "OK: Recycle Bin enabled"
101+
} else {
102+
Write-Output "KO: Recycle Bin disabled"
103+
$global:exitCode++
104+
}
105+
}
106+
}
107+
93108
# Check if Active Directory Domain Services feature is installed
94109
try {
95110
$adFeature = Get-WindowsFeature -Name AD-Domain-Services -ErrorAction Stop
@@ -114,6 +129,12 @@ try {
114129
Write-Host "GPO Versions checks"
115130
# Call the function to compare GPO versions
116131
Compare-GPOVersions
132+
133+
Write-Host ""
134+
Write-Host "Recycle Bin checks"
135+
# Call the function to check the Recycle Bin
136+
Check-ADRecycleBin
137+
117138
} else {
118139
Write-Host "Active Directory Domain Services feature is not installed or not in the 'Installed' state."
119140
exit

scripts_staging/TasksUpdater/Updater P3 Run SU.ps1

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@
1717
Schedules={{agent.Schedules}}
1818
Company_folder_path={{global.Company_folder_path}}
1919
20+
trmm_sign_download_token={{global.trmm_sign_download_token}}
21+
trmm_api_target={{global.RMM_API_URL}}
22+
2023
.NOTES
2124
Author: SAN // MSA
2225
Date: 06.08.2024
2326
Dependencies:
2427
Logging snippet for logging
2528
Updater P3.5 Schedules parser snippet for parsing the date
2629
CallPowerShell7 snippet to upgrade the script to pwsh
30+
Update TRMM agent snipper for agent upgrade
2731
#public
2832
2933
.CHANGELOG
@@ -33,6 +37,7 @@
3337
27.11.24 SAN More verbose output for the reboot and fixed some lack of logs from the Chocolatey commands.
3438
27.11.24 SAN Disabled file rename check due to issues.
3539
13.12.24 SAN Split logging from parser.
40+
06.03.25 SAN added TRMM agent updater.
3641
3742
.TODO
3843
Fix rename?
@@ -120,7 +125,7 @@ if ($result.RebootRequired) {
120125
Write-Host "No Reboot is pending BEFORE updates."
121126
}
122127

123-
# The following section is in place due to the fact that ps logging does not capture RAW output from choco
128+
# The following section is in place due to the fact that ps logging does not capture RAW output from choco please do not touch
124129
# List outdated packages and capture output
125130
$outdatedPackages = choco outdated | Out-String
126131
# Upgrade all packages and capture output
@@ -129,14 +134,17 @@ $upgradeResult = choco upgrade all -y | Out-String
129134
Write-Host ""
130135
Write-Host "------------------------------------------------------------"
131136
Write-Host ""
132-
Write-Host "Outdated Packages:"
137+
Write-Host "Chocolatey Outdated Packages before upgrade:"
133138
Write-Host $outdatedPackages
134139
Write-Host "------------------------------------------------------------"
135-
Write-Host "Upgrade Result:"
140+
Write-Host "Chocolatey Upgrade Result:"
136141
Write-Host $upgradeResult
137142
Write-Host ""
138143
Write-Host "------------------------------------------------------------"
139144
Write-Host ""
145+
Write-Host "------------------------------------------------------------"
146+
Write-Host "TRMM Agent update"
147+
{{Update TRMM agent}}
140148

141149

142150
# Check if a reboot is pending and reboot if necessary
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
<#
2+
.SYNOPSIS
3+
Downloads and installs the latest or specified version of the Tactical RMM agent, with support for signed and unsigned downloads.
4+
5+
.DESCRIPTION
6+
This script retrieves the latest version of the Tactical RMM agent from GitHub or downloads a specified version based on the input environment variables.
7+
It supports downloading a signed version using a provided token, or an unsigned version directly from GitHub.
8+
If the specified version is set to "latest," the script fetches the most recent release information.
9+
Before downloading, it checks the locally installed version from the software list and skips the download if it matches the desired version.
10+
11+
.PARAMETER version
12+
Specifies the version to download. If set to "latest," the script retrieves the latest version available on GitHub.
13+
This should be specified through the environment variable `version`.
14+
15+
.PARAMETER signedDownloadToken
16+
The token used for authenticated signed downloads. This should be set in the environment variable `trmm_sign_download_token`.
17+
If this token is provided, the script will download the signed version.
18+
19+
.PARAMETER trmm_api_target
20+
The API target required for signed downloads. This should be specified in the environment variable `trmm_api_target`.
21+
This is only necessary if using a signed download.
22+
23+
.EXEMPLE
24+
trmm_sign_download_token={{global.trmm_sign_download_token}}
25+
version=latest
26+
version=2.7.0
27+
trmm_api_target=api.exemple.com
28+
trmm_api_target={{global.RMM_API_URL}}
29+
30+
.NOTES
31+
Author: SAN
32+
Date: 29.10.24
33+
#public
34+
35+
.CHANGELOG
36+
29.10.24 SAN Initial script with signed and unsigned download support.
37+
21.12.24 SAN updated the script to not require "issigned"
38+
22.12.24 SAN default to latest when no version is set
39+
40+
.TODO
41+
Add a small (15 seconds) delay to the execution of the exe to ensure trmm is capable of properly capturing the output of the script before the agent kills the service
42+
43+
#>
44+
# Variables
45+
$version = $env:version # Specify a version manually, or leave empty to get the latest version from GitHub
46+
$signedDownloadToken = $env:trmm_sign_download_token # Token used for signed downloads only
47+
$apiTarget = $env:trmm_api_target # Environment variable for the API target URL
48+
49+
# Define GitHub API URL for the RMMAgent repository
50+
$repoUrl = "https://api.github.com/repos/amidaware/rmmagent/releases/latest"
51+
52+
# Function to get the currently installed version of the Tactical RMM agent from the software list
53+
function Get-InstalledVersion {
54+
$appName = "Tactical RMM Agent" # Adjust if the application's display name differs left this in case whitelabel changes the name of the app
55+
$installedSoftware = Get-CimInstance -ClassName Win32_Product | Where-Object { $_.Name -like "*$appName*" }
56+
57+
if ($installedSoftware) {
58+
return $installedSoftware.Version
59+
} else {
60+
# Check the uninstall registry key for a more complete list
61+
$uninstallKeys = @(
62+
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*",
63+
"HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
64+
)
65+
66+
foreach ($key in $uninstallKeys) {
67+
$installedSoftware = Get-ItemProperty $key | Where-Object { $_.DisplayName -like "*$appName*" }
68+
if ($installedSoftware) {
69+
return $installedSoftware.DisplayVersion
70+
}
71+
}
72+
73+
return $null
74+
}
75+
}
76+
77+
try {
78+
# Set up headers for GitHub API request
79+
$headers = @{
80+
"User-Agent" = "PowerShell Script"
81+
}
82+
83+
# If version is not set, default to "latest"
84+
if (-not $version) {
85+
$version = "latest"
86+
}
87+
if ($version -eq "latest") {
88+
Write-Output "Fetching the latest version information of the TRMM agent from GitHub..."
89+
$response = Invoke-RestMethod -Uri $repoUrl -Headers $headers -Method Get -ErrorAction Stop
90+
$version = $response.tag_name.TrimStart('v') # Remove 'v' prefix if exists
91+
Write-Output "Latest version found: $version"
92+
} else {
93+
Write-Output "Using specified version: $version"
94+
}
95+
96+
# Check if the installed version matches the desired version
97+
$installedVersion = Get-InstalledVersion
98+
if ($installedVersion) {
99+
Write-Output "Installed version of 'Tactical RMM Agent': $installedVersion"
100+
if ($installedVersion -eq $version) {
101+
Write-Output "The installed version matches the desired version. No upgrade required."
102+
exit 0
103+
} else {
104+
Write-Output "The installed version ($installedVersion) does not match the desired version ($version). Proceeding with download."
105+
}
106+
} else {
107+
Write-Output "'Tactical RMM Agent' is not installed on this system. Checking installed software..."
108+
}
109+
110+
# Define the temp directory for downloading
111+
$tempDir = [System.IO.Path]::GetTempPath()
112+
$outputFile = Join-Path -Path $tempDir -ChildPath "tacticalagent-v$version.exe"
113+
114+
# Determine the download URL based on the presence of $signedDownloadToken
115+
if ($signedDownloadToken) {
116+
if (-not $apiTarget) {
117+
Write-Output "Error: Missing API target for signed downloads. Exiting..."
118+
exit 1
119+
}
120+
# Download the signed agent using the token
121+
$downloadUrl = "https://agents.tacticalrmm.com/api/v2/agents?version=$version&arch=amd64&token=$signedDownloadToken&plat=windows&api=$apiTarget"
122+
} else {
123+
# Download the unsigned agent directly from GitHub releases
124+
$downloadUrl = "https://github.com/amidaware/rmmagent/releases/download/v$version/tacticalagent-v$version-windows-amd64.exe"
125+
}
126+
127+
Write-Output "Downloading from: $downloadUrl"
128+
129+
# Download the agent file
130+
try {
131+
Invoke-WebRequest -Uri $downloadUrl -OutFile $outputFile -ErrorAction Stop
132+
Write-Output "Download completed: $outputFile"
133+
} catch {
134+
Write-Output "Failed to download the agent. Error: $($_.Exception.Message)"
135+
exit 1
136+
}
137+
138+
# Run the downloaded file in a new context (using cmd)
139+
$processStartInfo = New-Object System.Diagnostics.ProcessStartInfo
140+
$processStartInfo.FileName = $outputFile
141+
$processStartInfo.Arguments = "/VERYSILENT"
142+
$processStartInfo.UseShellExecute = $true # Allows the executable to run independently
143+
$processStartInfo.CreateNoWindow = $true # Prevents a new window from being created
144+
145+
Write-Output "Starting installation..."
146+
147+
# Start the process without attempting to cast the result
148+
try {
149+
[System.Diagnostics.Process]::Start($processStartInfo)
150+
Write-Output "Installation started. The process is running in the background."
151+
} catch {
152+
Write-Output "Failed to start the installation process. Error: $($_.Exception.Message)"
153+
exit 1
154+
}
155+
} catch {
156+
# Handle unexpected errors with output
157+
Write-Output "An unexpected error occurred: $($_.Exception.Message)"
158+
exit 1
159+
}

0 commit comments

Comments
 (0)