Infrastructure-as-code framework for Active Directory objects and Group Policy. Sanitized from production deployment for public sharing.
46 lines
1.5 KiB
PowerShell
46 lines
1.5 KiB
PowerShell
# Install-RSAT.ps1
|
|
# GPO Startup Script — installs RSAT Features on Demand if not already present.
|
|
# Runs as SYSTEM at computer startup. Idempotent — safe to run repeatedly.
|
|
# Requires internet access (downloads from Windows Update).
|
|
|
|
$logFile = 'C:\PSlogs\RSAT-Install.log'
|
|
|
|
# Ensure log and transcript directories exist
|
|
$logDir = Split-Path $logFile -Parent
|
|
if (-not (Test-Path $logDir)) {
|
|
New-Item -ItemType Directory -Path $logDir -Force | Out-Null
|
|
}
|
|
$transcriptDir = 'C:\PSlogs\Transcripts'
|
|
if (-not (Test-Path $transcriptDir)) {
|
|
New-Item -ItemType Directory -Path $transcriptDir -Force | Out-Null
|
|
}
|
|
|
|
function Write-Log {
|
|
param([string]$Message)
|
|
$ts = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
|
|
"$ts $Message" | Out-File -Append -FilePath $logFile
|
|
}
|
|
|
|
Write-Log '=== RSAT Install Check Starting ==='
|
|
|
|
$rsatFeatures = Get-WindowsCapability -Name 'Rsat*' -Online |
|
|
Where-Object { $_.State -ne 'Installed' }
|
|
|
|
if ($rsatFeatures.Count -eq 0) {
|
|
Write-Log 'All RSAT features already installed. Nothing to do.'
|
|
} else {
|
|
Write-Log "$($rsatFeatures.Count) RSAT feature(s) not installed. Installing..."
|
|
foreach ($feature in $rsatFeatures) {
|
|
Write-Log " Installing: $($feature.Name)"
|
|
try {
|
|
Add-WindowsCapability -Online -Name $feature.Name -ErrorAction Stop | Out-Null
|
|
Write-Log " [OK] $($feature.Name)"
|
|
} catch {
|
|
Write-Log " [FAILED] $($feature.Name): $($_.Exception.Message)"
|
|
}
|
|
}
|
|
Write-Log 'RSAT installation pass complete.'
|
|
}
|
|
|
|
Write-Log '=== RSAT Install Check Finished ==='
|