Initial commit for powershell scripts.

This commit is contained in:
mattspeer committed 2026-10-04 10:22:22 -05:00
1 parent f4e5d9dcbd
commit 4fd95b76d6
18 files changed
+1803

No files matched your search

+56
View File
@@ -0,0 +1,56 @@
#Requires -RunAsAdministrator
<#
.SYNOPSIS
Configures static DNS server addresses on active network adapters.
.DESCRIPTION
This script retrieves all active (connected) network interfaces on the endpoint and assigns
primary DNS (Quad9) and secondary backup DNS (Cloudflare) servers.
.NOTES
Created: 2025-03-02
Modified: 2026-10-04
DNS Server Mappings:
- Quad9 Primary: 9.9.9.9 (Malware blocking + DNSSEC)
- Quad9 Secondary: 149.112.112.11 (Malware blocking + DNSSEC)
- Cloudflare Prim: 1.1.1.2 (Malware blocking)
- Cloudflare Sec: 1.0.0.2 (Malware blocking)
* Note: If adult content blocking is also desired via Cloudflare,
use 1.1.1.3 and 1.0.0.3 instead.
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param (
# Array of DNS IPv4 addresses in priority order
[string[]]$DnsServers = @("9.9.9.9", "149.112.112.11", "1.1.1.2", "1.0.0.2")
)
# 1. Retrieve active/connected network adapters (filters out disabled, virtual, or disconnected NICs)
$ActiveAdapters = Get-NetAdapter | Where-Object { $_.Status -eq 'Up' }
if (-not $ActiveAdapters) {
Write-Warning "No active network adapters found on this endpoint."
return
}
# 2. Apply DNS settings to each active interface
foreach ($Adapter in $ActiveAdapters) {
$InterfaceName = $Adapter.Name
$InterfaceIndex = $Adapter.InterfaceIndex
if ($PSCmdlet.ShouldProcess("Interface: $InterfaceName (Index: $InterfaceIndex)", "Set DNS servers to $($DnsServers -join ', ')")) {
try {
# Set the static DNS client addresses
Set-DnsClientServerAddress -InterfaceIndex $InterfaceIndex -ServerAddresses $DnsServers -ErrorAction Stop
Write-Host "Successfully updated DNS for '$InterfaceName' (Index: $InterfaceIndex)" -ForegroundColor Green
}
catch {
Write-Error "Failed to update DNS on interface '$InterfaceName' (Index: $InterfaceIndex). Error: $_"
}
}
}
+90
View File
@@ -0,0 +1,90 @@
#Requires -RunAsAdministrator
<#
.SYNOPSIS
Triggers the Windows TPM Health Attestation Certificate Retrieval scheduled task.
.DESCRIPTION
Executes the '\Microsoft\Windows\TPM\Tpm-HASCertRetr' scheduled task to resolve
BitLocker device registration, Health Attestation, or TPM certificate retrieval
issues on endpoints (frequently used in Microsoft Intune environments).
.NOTES
Created: 2025-01-15
Modified: 2026-10-04
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[string]$LogDirectory = "C:\IntuneLogs",
[string]$LogFileName = "BitlockerRegFix.log",
[string]$TaskPath = "\Microsoft\Windows\TPM\",
[string]$TaskName = "Tpm-HASCertRetr"
)
# Build full log file path
$LogPath = Join-Path -Path $LogDirectory -ChildPath $LogFileName
# Helper function for structured, timestamped logging
function Write-Log {
param (
[string]$Message,
[ValidateSet("INFO", "WARNING", "ERROR")]
[string]$Level = "INFO"
)
$Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$FormattedMessage = "[$Timestamp] [$Level] $Message"
# Write to console / verbose stream
if ($Level -eq "ERROR") {
Write-Error $Message
} elseif ($Level -eq "WARNING") {
Write-Warning $Message
} else {
Write-Host $FormattedMessage
}
# Append to log file safely
try {
if (-not (Test-Path -Path $LogDirectory)) {
New-Item -Path $LogDirectory -ItemType Directory -Force | Out-Null
}
Add-Content -Path $LogPath -Value $FormattedMessage -ErrorAction SilentlyContinue
}
catch {
# Fallback if logging fails
}
}
# --- Execution Logic ---
Write-Log "Starting BitLocker/TPM registration fix process..."
# 1. Verify scheduled task exists on the system
$Task = Get-ScheduledTask -TaskPath $TaskPath -TaskName $TaskName -ErrorAction SilentlyContinue
if (-not $Task) {
Write-Log "Scheduled task '$TaskPath$TaskName' was not found on this endpoint." -Level "ERROR"
exit 1
}
# 2. Trigger the scheduled task
if ($PSCmdlet.ShouldProcess("Scheduled Task: $TaskPath$TaskName", "Execute Task")) {
try {
Write-Log "Executing scheduled task '$TaskPath$TaskName'..."
# Trigger task run
Start-ScheduledTask -TaskPath $TaskPath -TaskName $TaskName -ErrorAction Stop
# Brief pause to verify task state
Start-Sleep -Seconds 2
$UpdatedTask = Get-ScheduledTask -TaskPath $TaskPath -TaskName $TaskName
Write-Log "Successfully triggered task. Current Task State: $($UpdatedTask.State)" -Level "INFO"
exit 0
}
catch {
Write-Log "Failed to execute scheduled task '$TaskPath$TaskName'. Error: $_" -Level "ERROR"
exit 1
}
}
+112
View File
@@ -0,0 +1,112 @@
#!/bin/bash
# ==============================================================================
# SSH Backup and Download Script
#
# Description:
# This script connects to a remote server to perform a backup, then downloads
# the backup files to the local machine. It uses SSH keys for secure,
# password-less authentication.
# 1. Connects via SSH to the remote server.
# 2. Zips a specified directory on the remote server.
# 3. Exports a WordPress database on the remote server.
# 4. Downloads the zipped directory to the local ~/Downloads folder.
# 5. Downloads the SQL database backup to the local ~/Downloads folder.
# 6. Removes the created backup files from the remote server.
#
# Usage:
# ./connect.sh
#
# ==============================================================================
# --- Configuration ---
# The username for the SSH connection.
USERNAME="mattspeer"
# The hostname or IP address of the server to connect to.
HOSTNAME="addsourcegroup.com"
# --- Main Execution ---
echo "Connecting to ${HOSTNAME} to run backup commands..."
# Define filenames that will be created on the remote server.
# This needs to be done locally to ensure the filenames match for removal.
DATE_STAMP=$(date +"%Y-%m-%d")
REMOTE_WEBSITE_BACKUP_FILENAME="addsourcegroup_com_${DATE_STAMP}.zip"
REMOTE_DB_BACKUP_FILENAME="db_backup_${DATE_STAMP}.sql"
# Use a Here Document (Heredoc) to pass a block of commands to the remote server.
# Using 'EOF' in quotes prevents the local shell from expanding variables,
# ensuring that commands like `date` are executed on the remote server.
# No password or password variable is needed due to SSH key authentication.
ssh "${USERNAME}@${HOSTNAME}" <<EOF_REMOTE_COMMANDS
# This entire block of commands runs on the remote server.
# Exit immediately if any command fails.
set -e
echo "--- Starting remote execution on $(hostname) ---"
# 1. Zip the website directory.
echo "Step 1: Zipping site files..."
zip -r ${REMOTE_WEBSITE_BACKUP_FILENAME} addsourcegroup.com
# 2. Change into the website directory.
echo "Step 2: Changing directory to addsourcegroup.com..."
cd addsourcegroup.com
# 3. Export the WordPress database using WP-CLI.
# The backup file will be saved in the remote user's home directory (~).
echo "Step 3: Exporting WordPress database..."
wp db export ~/${REMOTE_DB_BACKUP_FILENAME}
echo "--- Remote execution finished successfully! ---"
EOF_REMOTE_COMMANDS
# Check the exit status of the SSH command.
# Proceed only if the remote commands were successful (exit status 0).
if [ $? -eq 0 ]; then
echo "Remote backup successful. Starting local file downloads..."
# --- Local Download Commands ---
# These commands run on your local machine after the SSH session closes.
# 4. Download the zipped site files using scp.
echo "Step 4: Downloading site files (${REMOTE_WEBSITE_BACKUP_FILENAME}) to ~/OneDrive - Add Source Group/Documents/4 - Archive/Backups/ASG Website..."
scp "${USERNAME}@${HOSTNAME}:${REMOTE_WEBSITE_BACKUP_FILENAME}" ~/OneDrive\ -\ Add\ Source\ Group/Documents/4\ -\ Archive/Backups/ASG\ Website
# 5. Download the database backup using scp.
echo "Step 5: Downloading database backup (${REMOTE_DB_BACKUP_FILENAME}) to ~/OneDrive - Add Source Group/Documents/4 - Archive/Backups/ASG Website..."
scp "${USERNAME}@${HOSTNAME}:~/${REMOTE_DB_BACKUP_FILENAME}" ~/OneDrive\ -\ Add\ Source\ Group/Documents/4\ -\ Archive/Backups/ASG\ Website
# Final check to confirm downloads were successful.
if [ $? -eq 0 ]; then
echo "Backup script and downloads completed successfully."
echo "Attempting to remove backup files from the remote host..."
# --- Remote File Cleanup ---
# Connect again to remove the files. It's safer to do this after successful download.
ssh "${USERNAME}@${HOSTNAME}" <<EOF_CLEANUP
set -e
echo "Step 6: Removing remote backup files..."
rm -f ~/${REMOTE_WEBSITE_BACKUP_FILENAME}
rm -f ~/${REMOTE_DB_BACKUP_FILENAME}
echo "Remote cleanup complete."
EOF_CLEANUP
if [ $? -eq 0 ]; then
echo "Remote files removed successfully."
else
echo "WARNING: Could not remove remote files. Please check manually." >&2
fi
else
echo "An error occurred during the file download. Remote files were NOT removed." >&2
exit 1
fi
else
echo "An error occurred during the remote execution. Halting script." >&2
exit 1
fi