<# .PARAMETER agent_path Path for installed agent .PARAMETER gw_path Path to download the gateway .PARAMETER gw_version Version of the GDataGateway (to get file name) .PARAMETER source_path URL to download the file .PARAMETER destination_file Path to unzip the downloaded file .PARAMETER log_File Output logged to that filename .EXAMPLE .LINK VERSION 2th September 2024 | 09:45 AM | v1.0.4 #> # Log all information into that file $log_File = "C:\Temp\Get-GDataGateway_v" # RMM Agent Folders $agent_path = "C:\Program Files (x86)\Riverbird\Agents" # GDataGateway Version $gw_version = "1.1.42.0" $gw_file = "$gw_version.zip" # Source Path and File $source_path = "https://packages.riverbird.de/monitoring/plugins/GDataGateway/versions" $source_file = "$source_path/$gw_file" # Function to generate Message in Log function log_Output { Param ( $output ) # Current date $date = (Get-Date -format "yyyy-MM-dd_HH-mm-ss") $ldate = (Get-Date -format "yyyy-MM-dd_HH-mm") # RMM Agent Log $log_File = "{0}{1}-{2}.log" -f $log_File, $gw_version, $ldate # Format a log message $message = "{0}: {1}" -f $date, $($output) $message = $message | Out-File $log_file -Append return $message } # Function to get the version of the running RMM Agent UI function get_RMM.Agent_UI_Version { # RMM Agent UI $agent_ui = "RMM.Agent.UI" # Return RMM Agent UI version $result = (Get-Process $agent_ui).FileVersion $result = $result.ToString().Split('+')[0].Trim() return $result } $agent_ui = get_RMM.Agent_UI_Version $gw_path = "$agent_path\v$agent_ui\plugins\GDataGateway" # Destination File $destination_file = "$gw_path\$gw_file" # Download archive from URL function Download { # Check if folder plugins\Gateway exists if (! (Test-Path -Path $gw_path)) { # Create non existing folder New-Item -type Directory -Force -Path $gw_path # Build a message string $message = "Create non existing folder: {0}" -f $gw_path # Log message to a protocol log_Output $message } # Download GDataGateway (~ 100 MB) if (Test-Path -Path $gw_path -PathType Container) { # Change to folder Set-Location -Path $gw_path # Download file Invoke-WebRequest $source_file -OutFile $destination_file # Build a message string $message = "Download successful: {0}" -f $destination_file # Log message to a protocol log_Output $message # Print message to stdout Write-Output $message } } # Unzip downloaded archive function Unzip { # Unzip GDataGateway if (Test-Path -Path $destination_file -PathType Leaf) { cd $gw_path ; Expand-Archive -Path $gw_file -DestinationPath $gw_path\$gw_version -Force # Build a message string $message = "Unzip successful: {0}\{1}" -f $gw_path, $gw_version # Log message to a protocol log_Output $message # Print message to stdout Write-Output $message } } # Main Download Unzip exit 0