Next, from the automating post we now need a PowerShell script to systematically retrieve automated update log files from multiple macOS devices across different locations. This script addresses the operational requirement to centrally collect and analyze update logs from distributed macOS systems.
Functionality Overview
The script connects to remote macOS devices and downloads the /var/log/automated_updates.log
file from each system. I designed it to handle multiple servers simultaneously while maintaining proper file organization and naming conventions.
Remote File Retrieval
The script uses PuTTY's secure copy utility to transfer files from remote macOS systems:
$PuttyPath = "C:\Program Files\PuTTY\pscp.exe"
Credential Management
I implemented secure credential handling through XML import:
$Credential = Import-Clixml -Path $CredentialFile
$Username = $Credential.UserName
$Password = $Credential.GetNetworkCredential().Password
Server Configuration
The script targets multiple locations across major US cities:
$Servers = @{
"192.168.45.12" = "Chicago"
"10.147.88.203" = "Phoenix"
"172.16.92.156" = "Houston"
"10.89.134.67" = "Philadelphia"
"192.168.71.91" = "San.Antonio"
"172.20.58.144" = "San.Diego"
}
File Organization
The script creates and populates a dedicated directory structure:
$OutputFolder = "AutomatedUpdates"
if (!(Test-Path -Path $OutputFolder)) {
New-Item -ItemType Directory -Path $OutputFolder -Force
}
All retrieved log files are stored in the AutomatedUpdates
folder with systematic naming that includes:
- Current date prefix (YYYY-MM-DD format)
- Location identifier
- Original filename
Technical Implementation
Date-based Naming
I incorporated automatic date prefixing to ensure chronological organization:
$DatePrefix = Get-Date -Format "yyyy-MM-dd"
$LocalFileName = "$DatePrefix-$ServerName-automated_updates.log"
Error Handling
The script includes comprehensive error handling for connection failures and file transfer issues:
try {
$Result = & $PuttyPath -batch -pw $Password "$Username@${RemoteHost}:/var/log/automated_updates.log" $LocalFilePath
if ($LASTEXITCODE -eq 0) {
Write-Host "Successfully retrieved log file from $ServerName"
} else {
Write-Host "ERROR: Failed to retrieve log file from $ServerName"
}
}
catch {
Write-Host "ERROR: Connection failed to $ServerName: $_"
}
Execution Process
- Script validates and creates the AutomatedUpdates output directory
- Imports stored credentials from XML file
- Iterates through each configured server
- Establishes secure connection using pscp
- Downloads
/var/log/automated_updates.log
from each system - Saves files with date-prefixed naming convention
- Provides status feedback for each operation
This automated approach ensures consistent log collection across all managed macOS systems while maintaining proper file organization and audit trails. Part 2 will cover creating an HTML dashboard to visualize and analyze the collected update data.