Initial commit - added autorun post OOBE script

This commit is contained in:
Kyle Pope 2025-04-11 10:07:35 +08:00
commit 5f4716e4a7

101
Generic-Setup.ps1 Normal file
View File

@ -0,0 +1,101 @@
# Ensure the log directory exists
$logDirectory = "C:\Logs"
if (-not (Test-Path -Path $logDirectory)) {
try {
New-Item -ItemType Directory -Path $logDirectory -Force | Out-Null
Write-Host "INFO: Created log directory at $logDirectory"
} catch {
Write-Host "ERROR: Failed to create log directory at $logDirectory - $_"
exit 1
}
}
# Define the log file path with a timestamp
$logFile = Join-Path -Path $logDirectory -ChildPath "GeneralSetup_$(Get-Date -Format 'ddMMyyyy_HHmm').log"
# Function to write logs with different levels
function Write-Log {
param (
[Parameter(Mandatory=$true)]
[string]$Message,
[Parameter(Mandatory=$false)]
[ValidateSet("INFO", "WARNING", "ERROR")]
[string]$Level = "INFO"
)
# Prefix the message based on the level
switch ($Level) {
"ERROR" { $logMessage = "ERROR: $Message" }
"WARNING" { $logMessage = "WARNING: $Message" }
default { $logMessage = "INFO: $Message" }
}
# Add timestamp
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$logEntry = "[$timestamp] $logMessage"
# Write to log file
Add-Content -Path $logFile -Value $logEntry
# Also output to console for visibility
Write-Output $logEntry
}
try {
Write-Log -Message "Starting script to configure timezone, locale, and region settings." -Level "INFO"
# Set the time zone to Australia/Perth
try {
Set-TimeZone -Id "W. Australia Standard Time" -ErrorAction Stop
Write-Log -Message "Successfully set timezone to 'W. Australia Standard Time'." -Level "INFO"
} catch {
Write-Log -Message "Failed to set timezone: $_" -Level "ERROR"
}
# Set the system locale to English (Australia)
try {
Set-WinSystemLocale -SystemLocale en-AU -ErrorAction Stop
Write-Log -Message "Successfully set system locale to 'en-AU'." -Level "INFO"
} catch {
Write-Log -Message "Failed to set system locale: $_" -Level "ERROR"
}
# Set the user locale to English (Australia)
try {
Set-WinUserLanguageList -LanguageList en-AU -Force -ErrorAction Stop
Write-Log -Message "Successfully set user language list to 'en-AU'." -Level "INFO"
} catch {
Write-Log -Message "Failed to set user language list: $_" -Level "ERROR"
}
# Set the culture to English (Australia)
try {
Set-Culture -CultureInfo en-AU -ErrorAction Stop
Write-Log -Message "Successfully set culture to 'en-AU'." -Level "INFO"
} catch {
Write-Log -Message "Failed to set culture: $_" -Level "ERROR"
}
# Set the region settings to Australia (GeoId 12)
try {
Set-WinHomeLocation -GeoId 12 -ErrorAction Stop
Write-Log -Message "Successfully set region settings to Australia (GeoId: 12)." -Level "INFO"
} catch {
Write-Log -Message "Failed to set region settings: $_" -Level "ERROR"
}
# Synchronize the system clock with an NTP server (optional)
try {
w32tm /resync | Out-Null
Write-Log -Message "Successfully synchronized system clock with NTP server." -Level "INFO"
} catch {
Write-Log -Message "Failed to synchronize system clock: $_" -Level "WARNING"
}
Write-Log -Message "Date, time, locale, and region settings have been set to Australia/Perth." -Level "INFO"
} catch {
Write-Log -Message "An unexpected error occurred in the script: $_" -Level "ERROR"
} finally {
Write-Log -Message "Script execution completed." -Level "INFO"
}