diff --git a/api/tacticalrmm/scripts/community_scripts.json b/api/tacticalrmm/scripts/community_scripts.json index bff4e120..64c3f3c1 100644 --- a/api/tacticalrmm/scripts/community_scripts.json +++ b/api/tacticalrmm/scripts/community_scripts.json @@ -410,14 +410,14 @@ "category": "TRMM (Win):Other" }, { - "guid": "5615aa90-0272-427b-8acf-0ca019612501", - "filename": "Win_Chocolatey_Update_Installed.bat", + "guid": "6c78eb04-57ae-43b0-98ed-cbd3ef9e2f80", + "filename": "Win_Chocolatey_Manage_Apps_Bulk.ps1", "submittedBy": "https://github.com/silversword411", - "name": "Update Installed Apps", - "description": "Update all apps that were installed using Chocolatey.", - "shell": "cmd", + "name": "Chocolatey - Install, Uninstall and Upgrade Software", + "description": "This script installs, uninstalls and updates software using Chocolatey with logic to slow tasks to minimize hitting community limits. Mode install/uninstall/upgrade Hosts x", + "shell": "powershell", "category": "TRMM (Win):3rd Party Software>Chocolatey", - "default_timeout": "3600" + "default_timeout": "600" }, { "guid": "fff8024d-d72e-4457-84fa-6c780f69a16f", diff --git a/scripts/Win_Chocolatey_Manage_Apps_Bulk.ps1 b/scripts/Win_Chocolatey_Manage_Apps_Bulk.ps1 new file mode 100644 index 00000000..d49de0c7 --- /dev/null +++ b/scripts/Win_Chocolatey_Manage_Apps_Bulk.ps1 @@ -0,0 +1,55 @@ +<# + .SYNOPSIS + This will install software using the chocolatey, with rate limiting when run with Hosts parameter + .DESCRIPTION + For installing packages using chocolatey. If you're running against more than 10, includ the Hosts parameter to limit the speed + .PARAMETER Mode + 3 options: install (default), uninstall, or upgrade. + .PARAMETER Hosts + Use this to specify the computer(s) you're running the command on: Hosts 20 + .PARAMETER PackageName + Use this to specify which software to install eg: PackageName googlechrome + .EXAMPLE + Hosts 20 PackageName googlechrome + .EXAMPLE + Mode upgrade Hosts 50 + .EXAMPLE + Mode uninstall PackageName googlechrome + #> + +param ( + [string] $Hosts = "0", + [string] $PackageName, + [string] $Mode = "install", +) + +$ErrorCount = 0 + +if (!$PackageName) { + write-output "No choco package name provided, please include Example: `"PackageName googlechrome`" `n" + $ErrorCount += 1 +} + +if (!$Mode -eq "upgrade") { + $randrange = ($Hosts + 1) * 10 + $rnd = Get-Random -Minimum 1 -Maximum $randrange; + Start-Sleep -Seconds $rnd; + choco ugrade -y all + Write-Output "Running upgrade" + Exit 0 +} + +if (!$Hosts -eq "0") { + write-output "No Hosts Specified, running concurrently" + choco $Mode $PackageName -y + Exit 0 +} +else { + $randrange = ($Hosts + 1) * 6 + $rnd = Get-Random -Minimum 1 -Maximum $randrange; + Start-Sleep -Seconds $rnd; + choco $Mode $PackageName -y + Exit 0 +} + +Exit $LASTEXITCODE \ No newline at end of file diff --git a/scripts/Win_Chocolatey_Update_Installed.bat b/scripts/Win_Chocolatey_Update_Installed.bat deleted file mode 100644 index e4fcd753..00000000 --- a/scripts/Win_Chocolatey_Update_Installed.bat +++ /dev/null @@ -1 +0,0 @@ -cup all -y