Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions scripts_staging/Collectors/SU update list.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<#
.SYNOPSIS
Checks for outdated Chocolatey packages and lists them.

.DESCRIPTION
This script verifies that Chocolatey is installed on the system.
If installed, it retrieves and displays a list of packages that have available updates.
If no packages are outdated, it confirms that all packages are up to date.
If Chocolatey is not installed or an error occurs, it exits with an error message.


.NOTES
Author: SAN
Date: 01.01.2024
#public

.CHANGELOG
19.10.25 SAN Code cleanup and add output if up-to-date

#>

# Check if Chocolatey is installed
if (-not (Get-Command choco -ErrorAction SilentlyContinue)) {
Write-Host "Chocolatey is not installed. Please install Chocolatey to use this script."
exit 1
}

# Get a list of upgradable packages
$upgradablePackages = choco outdated 2>$null

# Check the output and display results
if ($upgradablePackages -match "Chocolatey has determined 0 package") {
Write-Host "All up-to-date"
exit 0
}
elseif ($upgradablePackages) {
Write-Host "Upgradable packages:`n"
$upgradablePackages -split "`r?`n" | Select-Object -Skip 1 | ForEach-Object {
if ($_ -and ($_ -notmatch "Chocolatey has determined")) {
Write-Host $_
}
}
exit 0
}
else {
Write-Host "Error: Unable to determine upgradable packages."
exit 1
}
104 changes: 104 additions & 0 deletions scripts_staging/Tools/DNS Cache inspector.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<#
.SYNOPSIS
This script inspects and displays the Windows DNS client cache entries using either
`Get-DnsClientCache` (preferred) or by parsing the output of `ipconfig /displaydns` (fallback).

.DESCRIPTION
The script queries the local DNS client cache to show cached domain entries, record types,
record data, and TTL values. If the PowerShell cmdlet `Get-DnsClientCache` is unavailable,
the script falls back to parsing the `ipconfig /displaydns` output.

The script supports filtering cache entries based on a target string provided
through the environment variable `DNS_TARGET`.
If no environment variable is set, it defaults to `*` (all entries).

.EXAMPLE
DNS_TARGET=*.microsoft.com

.NOTE
Author: SAN
Date: 01.10.25
#Public

.CHANGELOG

#>

# Get filter target from environment variable
$Filter = $env:DNS_TARGET
if ([string]::IsNullOrWhiteSpace($Filter)) {
$Filter = '*'
}

Write-Host ''
Write-Host '--- Windows DNS Cache Inspector ---'
Write-Host 'Target filter:' $Filter
Write-Host ''

# Try Get-DnsClientCache first
try {
$results = Get-DnsClientCache -ErrorAction Stop | Where-Object {
($_.Name -like $Filter) -or ($_.RecordData -like $Filter) -or ($_.RecordType -like $Filter)
} | Select-Object Name, Entry, RecordType, RecordData,
@{Name='TTL';Expression={$_.TimeToLive}},
Section, Status
} catch {
$results = @()
}

# Fallback to ipconfig /displaydns
if (-not $results -or $results.Count -eq 0) {
Write-Host 'No results from Get-DnsClientCache, falling back to ipconfig parsing...'

$raw = ipconfig /displaydns 2>&1
$blocks = -split ($raw -join "`n"), "`n`r?`n"

$results = @()
foreach ($b in $blocks) {
$lines = $b -split "`r?`n" | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne '' }
if ($lines.Count -eq 0) { continue }

$entry = [PSCustomObject]@{
Name = $null
RecordType = $null
RecordData = $null
TTL = $null
CacheEntryType = $null
Section = $null
}

foreach ($line in $lines) {
if ($line -match 'Record Name\s*:\s*(.+)$') { $entry.Name = $matches[1].Trim() }
elseif ($line -match 'Record Type\s*:\s*(.+)$') { $entry.RecordType = $matches[1].Trim() }
elseif ($line -match 'Time To Live\s*:\s*(\d+)') { $entry.TTL = [int]$matches[1] }
elseif ($line -match 'Data:\s*(.+)$') { $entry.RecordData = $matches[1].Trim() }
elseif ($line -match 'A\s+Record\s*:\s*(.+)$') { $entry.RecordData = $matches[1].Trim() }
elseif ($line -match 'Cache Entry Type\s*:\s*(.+)$') { $entry.CacheEntryType = $matches[1].Trim() }
elseif ($line -match 'Section\s*:\s*(.+)$') { $entry.Section = $matches[1].Trim() }
}

if ($entry.Name) { $results += $entry }
}

if ($Filter -ne '*') {
$results = $results | Where-Object {
($_.Name -like $Filter) -or ($_.RecordData -like $Filter) -or ($_.RecordType -like $Filter)
}
}
}

# Output
$results = $results | Sort-Object Name
Write-Host ''
Write-Host 'Entries found:' $results.Count
Write-Host ''

if ($results.Count -gt 0) {
$results | Format-Table -AutoSize
Write-Host ''
Write-Host 'Match found — exiting with code 1.'
exit 1
} else {
Write-Host 'No DNS cache entries found.'
exit 0
}