-
Notifications
You must be signed in to change notification settings - Fork 0
[pull] main from amidaware:main #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a784e1a
a2bb5d8
66ea663
d5b82b4
8561266
38e776d
578bf6c
d94e1d7
a767b1d
c72e55d
28e8b3e
6a01b87
be5c38e
193d14b
366309b
5f3eeff
d446b64
5c78108
f3d01a7
80d9bb0
451e22c
af823d2
caf39a9
174274c
77f383c
adcbc33
490fcb5
e06db65
45eacf3
c29ad0b
a0946d5
742a3ec
40e9386
fff3630
957529d
1025263
6e92d0f
9ec99a5
140dcf7
7bc0a80
6e7f6c5
fa458f7
99d4837
bb3eb54
f5557b8
f15fca4
e90de38
ebced20
a3993d2
df8edf5
0f40ca6
f165f78
1822b83
004d652
59d637e
bcaff03
4b6f5b7
9c099cd
3a5efbf
af616ed
11b5926
3920ccf
8bbaf1e
18fecae
c7c7c80
39a0847
0e31d09
f5e4564
70f146b
f01f424
91c1e20
47e227a
f3b71f2
39773e4
6d53ffe
dc41534
6b9d2ae
8c64f8e
0511638
680cdaa
3ed646c
dc840c1
a65ebb7
64543ef
e44197b
df70076
3e02e39
238a182
94a585c
30afc92
5c59fac
16f217f
1c81d90
bc172d6
8129d4a
518b693
d72880b
0f7eca5
098a8c1
eb0076d
94cf346
0986434
5866600
d5e32f7
ffe1f8d
ed4d35f
c227d01
f6cc48b
ee91251
c7d9100
668755c
f957ff2
23dc45b
a367c63
bb1fffd
c6b85d6
90f41b1
b221d1e
f37bdfc
1ce392e
f925800
ff4aa64
7ecf685
4b3f5d5
f86eed0
9b52af8
e758072
398adb0
e621b49
c3d76b6
f7e5fdc
f4bdb1c
cac8387
eaeac5b
1505323
364dcdc
97d9a65
7298085
df58240
d41e4c3
e45551f
3dca8c8
3dae25a
7d6f169
1b10249
8c38b69
0deff80
d354db0
57daacd
0830d29
37c91e1
70cc2e7
3017648
18525f4
9909ca8
ceac534
f4ef928
d9d6f36
b44477b
c213cab
4f67dbc
8cac05c
217db59
4211d4a
469e6f7
ac80392
911f424
3ccb467
111dde7
21cbb05
7f9bcd6
eae28d2
f477e08
d842f70
5c58624
8d80ca3
527c98b
224999d
750a0fb
bf867b7
9f7053b
2924d53
37287b2
1a7ccfe
aa87320
1fcc8c1
2627c79
4c7fb7f
f083141
a43d3bf
7b55679
f790b30
87f1516
d440520
c9456fe
3c3a670
02beccd
7c79608
0da2263
e13b220
4cbe674
6faeb93
47f5d1e
c8d3079
9458206
70643b3
4440f1c
b924781
8506c83
c3a7e79
d0f34c9
ee77fb4
8e14093
03176ff
e2d22b1
9378ed7
382dbce
e96e513
93108ba
68088c6
79b1ebe
cd3670c
f2a03c4
8fe47f2
073de76
f7fc17f
076219c
d846804
b276122
68fa0ac
5e45df7
86c761d
d8809ca
626fbe0
51a6dae
47c5a25
bee5c32
0fef93c
d303d9b
2a8cd90
3255198
90758bb
526ffcd
3160e96
503c48e
85471d7
302ac23
c41590e
b4f2c53
8840d92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,32 +2,43 @@ | |
| .Synopsis | ||
| Bluescreen - Reports bluescreens | ||
| .DESCRIPTION | ||
| This will check for Bluescreen events on your system. If parameter provided, goes back that number of days | ||
| This script checks for Bluescreen events on your system. If a parameter is provided, it goes back that number of days to check. | ||
| .EXAMPLE | ||
| 365 | ||
| .NOTES | ||
| v1 bbrendon 2/2021 | ||
| v1.1 silversword updating with parameters 11/2021 | ||
| v1.1 silversword updating with parameters 11/2021 | ||
| v1.2 dinger1986 Updated for improved filtering and structure 11/2024 | ||
| #> | ||
|
|
||
| # Get the parameter (number of days to go back) | ||
| $DaysBack = $args[0] | ||
|
|
||
| $param1 = $args[0] | ||
| # Set error handling preference | ||
| $ErrorActionPreference = 'SilentlyContinue' | ||
|
|
||
| $ErrorActionPreference = 'silentlycontinue' | ||
| # Determine the time range based on the parameter | ||
| if ($Args.Count -eq 0) { | ||
| $TimeSpan = (Get-Date) - (New-TimeSpan -Day 1) | ||
| } | ||
| else { | ||
| $TimeSpan = (Get-Date) - (New-TimeSpan -Day $param1) | ||
| $StartTime = (Get-Date).AddDays(-1) | ||
| } else { | ||
| $StartTime = (Get-Date).AddDays(-[int]$DaysBack) | ||
| } | ||
|
|
||
| # Retrieve Bluescreen events | ||
| $BlueScreenEvents = Get-WinEvent -FilterHashtable @{ | ||
| LogName = 'Application'; | ||
| ID = 1001; | ||
| ProviderName = 'Windows Error Reporting'; | ||
| Level = 4; | ||
| StartTime = $StartTime | ||
| } | Where-Object { $_.Message -like "*BlueScreen*" } | ||
|
|
||
| if (Get-WinEvent -FilterHashtable @{LogName = 'application'; ID = '1001'; ProviderName = 'Windows Error Reporting'; Level = 4; Data = 'BlueScreen'; StartTime = $TimeSpan }) { | ||
| Write-Output "There has been bluescreen events detected on your system" | ||
| Get-WinEvent -FilterHashtable @{LogName = 'application'; ID = '1001'; ProviderName = 'Windows Error Reporting'; Level = 4; Data = 'BlueScreen'; StartTime = $TimeSpan } | ||
| # Check and output results | ||
| if ($BlueScreenEvents) { | ||
| Write-Output "There have been Bluescreen events detected on your system:" | ||
| $BlueScreenEvents | Format-List TimeCreated, Id, LevelDisplayName, Message | ||
| exit 1 | ||
| } else { | ||
| Write-Output "No bluescreen events detected in the past 24 hours." | ||
| Write-Output "No Bluescreen events detected in the past $((Get-Date) - $StartTime).Days days." | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Days calculation outputs object type instead of numberThe string interpolation |
||
| exit 0 | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| rem List apps installed by Chocolatey | ||
|
|
||
| choco list --local-only | ||
| set "chocoExePath=%PROGRAMDATA%\chocolatey\choco.exe" | ||
|
|
||
| "%chocoExePath%" list |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,71 +1,127 @@ | ||
| <# | ||
| .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, include the Hosts parameter to limit the speed. If running on more than 30 agents at a time make sure you also change the script timeout setting. | ||
| .PARAMETER Mode | ||
| 3 options: install (default), uninstall, or upgrade. | ||
| .PARAMETER Hosts | ||
| Use this to specify the number of computer(s) you're running the command on. This will dynamically introduce waits to try and minimize the chance of hitting rate limits (20/min) on the chocolatey.org site: Hosts 20 | ||
| .PARAMETER PackageName | ||
| Use this to specify which software('s) to install eg: PackageName googlechrome. You can use multiple values using comma separated. | ||
| .EXAMPLE | ||
| -Hosts 20 -PackageName googlechrome | ||
| -Hosts 30 -PackageName googlechrome,vlc | ||
| .EXAMPLE | ||
| -Mode upgrade -Hosts 50 | ||
| .EXAMPLE | ||
| -Mode upgrade -Hosts 50 -PackageName chocolatey | ||
| .EXAMPLE | ||
| -Mode uninstall -PackageName googlechrome | ||
| .NOTES | ||
| 9/2021 v1 Initial release by @silversword411 and @bradhawkins | ||
| 11/14/2021 v1.1 Fixing typos and logic flow | ||
| #> | ||
| .SYNOPSIS | ||
| Installs, uninstalls, upgrades, or lists software with rate limiting when run with Hosts parameter | ||
| .DESCRIPTION | ||
| This script uses Chocolatey to manage software packages. It introduces rate limiting when run on multiple hosts to avoid hitting rate limits at chocolatey.org. Use the Hosts parameter to specify the number of computers the script is running on. | ||
| .PARAMETER Mode | ||
| 5 modes: 'install' (default), 'uninstall', 'upgrade', 'upgrade-only-installed' or 'list'. | ||
| Mode 'install' installs the software specified by "PackageName" | ||
| Mode 'uninstall' removes the software specified by "PackageName" | ||
| Mode 'upgrade' checks for newer version and upgrades the package(s). If package is not existing on system it gets installed (default behaviour of chocolatey). If no PackageName is given all installed packages are being updated. | ||
| Mode 'upgrade-only-installed' checks for newer version of the package(s) and upgrades it. It will _not_ install new software (by adding --failonnotinstalled to the choco-command). | ||
| Mode 'list' lists packages which are installed by chocolatey on the target | ||
| Mode 'list-upgradeable' lists packages which are installed by chocolatey on the target but have updates available | ||
| .PARAMETER Hosts | ||
| Use this to specify the number of computer(s) you're running the command on. This will dynamically introduce waits to try and minimize the chance of hitting rate limits (20/min) on the chocolatey.org site: Hosts 20 | ||
| .PARAMETER PackageName | ||
| Use this to specify which software('s) to install eg: PackageName googlechrome. You can use multiple values using comma separated. | ||
| .EXAMPLE | ||
| -Hosts 20 -PackageName googlechrome | ||
| .EXAMPLE | ||
| -Mode upgrade -Hosts 50 -PackageName chocolatey | ||
| .EXAMPLE | ||
| -Mode upgrade-only-installed -Hosts 20 -PackageName googlechrome,firefox | ||
| .EXAMPLE | ||
| -Mode list | ||
| .NOTES | ||
| 9/2021 v1 Initial release by @silversword411 and @bradhawkins | ||
| 11/14/2021 v1.1 Fixing typos and logic flow | ||
| 12/8/2023 v1.3 Adding list, making choco full path | ||
| 2/22/2024 v1.4 Adding 'upgrade-only-installed' as mode by @derfladi | ||
| 3/5/2024 v1.5 silversword411 Adding --no-progress to minimize output | ||
| 5/21/2024 v1.6 silversword411 Adding list-upgradeable | ||
| #> | ||
|
|
||
| param ( | ||
| [Int] $Hosts = "0", | ||
| [Parameter(Mandatory = $false)] | ||
| [int] $Hosts = 0, | ||
|
|
||
| [Parameter(Mandatory = $false)] | ||
| [string[]] $PackageName, | ||
|
|
||
| [Parameter(Mandatory = $false)] | ||
| [ValidateSet("install", "uninstall", "upgrade", "upgrade-only-installed", "list", "list-upgradeable")] | ||
| [string] $Mode = "install" | ||
| ) | ||
|
|
||
| $ErrorCount = 0 | ||
| $chocoExePath = "$env:PROGRAMDATA\chocolatey\choco.exe" | ||
|
|
||
| if ($Mode -ne "upgrade" -and !$PackageName) { | ||
| write-output "No choco package name provided, please include Example: `"-PackageName googlechrome`" `n" | ||
| if (-not (Test-Path $chocoExePath)) { | ||
| Write-Host "Chocolatey is not installed." | ||
| Exit 1 | ||
| } | ||
|
|
||
| if ($Hosts -ne "0") { | ||
| $randrange = ($Hosts + 1) * 6 | ||
| # Write-Output "Calculating rnd" | ||
| # Write-Output "randrange $randrange" | ||
| $rnd = Get-Random -Minimum 1 -Maximum $randrange; | ||
| # Write-Output "rnd=$rnd" | ||
| } | ||
| else { | ||
| $rnd = "1" | ||
| # Write-Output "rnd set to 1 manually" | ||
| # Write-Output "rnd=$rnd" | ||
| $ErrorCount = 0 | ||
|
|
||
| if ($Mode -ne "upgrade" -and $Mode -ne "upgrade-only-installed" -and $Mode -ne "list" -and $Mode -ne "list-upgradeable" -and -not $PackageName) { | ||
| Write-Host "Error: No package name provided. Please specify a package name, e.g., `-PackageName googlechrome`." | ||
| Exit 1 | ||
| } | ||
|
|
||
| if ($Mode -eq "upgrade") { | ||
| # Write-Output "Starting Upgrade" | ||
| Start-Sleep -Seconds $rnd; | ||
| if (!$PackageName) { | ||
| choco upgrade -y all | ||
| # Calculate random delay based on the number of hosts | ||
| $randDelay = if ($Hosts -gt 0) { Get-Random -Minimum 1 -Maximum (($Hosts + 1) * 6) } else { 1 } | ||
|
|
||
| Write-Host "Sleeping $randDelay seconds" | ||
| Start-Sleep -Seconds $randDelay | ||
|
|
||
| switch ($Mode) { | ||
| "install" { | ||
| if ($PackageName) { | ||
| foreach ($package in $PackageName) { | ||
| & $chocoExePath install $package -y --no-progress | ||
| if ($LASTEXITCODE -ne 0) { $ErrorCount++ } | ||
| } | ||
| } | ||
| } | ||
| "uninstall" { | ||
| if ($PackageName) { | ||
| foreach ($package in $PackageName) { | ||
| & $chocoExePath uninstall $package -y | ||
| if ($LASTEXITCODE -ne 0) { $ErrorCount++ } | ||
| } | ||
| } | ||
| } | ||
| "upgrade" { | ||
| if ($PackageName) { | ||
| foreach ($package in $PackageName) { | ||
| & $chocoExePath upgrade $package -y --no-progress | ||
| if ($LASTEXITCODE -ne 0) { $ErrorCount++ } | ||
| } | ||
| } | ||
| else { | ||
| & $chocoExePath upgrade all -y --no-progress | ||
| } | ||
| } | ||
| else { | ||
| foreach ($package in $PackageName) | ||
| { | ||
| choco upgrade $package -y | ||
| "upgrade-only-installed" { | ||
| if ($PackageName) { | ||
| foreach ($package in $PackageName) { | ||
| & $chocoExePath upgrade $package --failonnotinstalled -y | ||
| if ($LASTEXITCODE -ne 0) { $ErrorCount++ } | ||
| } | ||
| } | ||
| else { | ||
| & $chocoExePath upgrade all --failonnotinstalled -y | ||
| } | ||
| } | ||
| "list" { | ||
| & $chocoExePath list | ||
| } | ||
| # Write-Output "Running upgrade" | ||
| Exit 0 | ||
| "list-upgradeable" { | ||
| & $chocoExePath outdated | ||
| } | ||
| } | ||
|
|
||
| if ($ErrorCount -gt 0) { | ||
| Write-Host "$ErrorCount errors occurred during the operation." | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Script exits successfully even when errors occurThe script always exits with code 0 via |
||
| } | ||
|
|
||
| # write-output "Running install/uninstall mode" | ||
| Start-Sleep -Seconds $rnd; | ||
| choco $Mode $PackageName -y | ||
| Exit 0 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Missing exit in non-customField success path
When antivirus is found and
$customFieldis not specified, the script outputs the antivirus information but never explicitly exits. The script then falls through without an exit code, potentially causing issues with how the calling system interprets the result. The$customFieldpath correctly usesexit 0, but the else branch is missing an exit statement.