Configuration FileOperations { param( [string]$ScriptDir ) Import-DscResource -ModuleName PSDesiredStateConfiguration # Calculate paths outside of Script resources $FontsPath = Join-Path $ScriptDir "Fonts" $FastStonePath = Join-Path $ScriptDir "FastStone" $FirefoxPath = Join-Path $ScriptDir "Firefox\policies.json" $ShareXAppConfigPath = Join-Path $ScriptDir "ShareX\ApplicationConfig.json" $ShareXHotkeysPath = Join-Path $ScriptDir "ShareX\HotkeysConfig.json" $PowerToysPath = Join-Path $ScriptDir "PowerToys\settings_133974244713307595.ptb" Node localhost { # === FONT INSTALLATION === # Install all Unifont files using Script resource for dynamic paths Script InstallUnifontFonts { SetScript = { $fontSourceFolder = $using:FontsPath $fontDestFolder = "C:\Windows\Fonts" $regPath = "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Fonts" # List of font files to install $fontFiles = @( "unifont-15.1.05.ttf", "unifont-all.ttf", "unifont-smooth.ttf", "unifont_csur-15.1.05.ttf", "unifont_jp-15.1.05.ttf", "unifont_upper-15.1.05.ttf" ) foreach ($fontFile in $fontFiles) { $sourcePath = Join-Path $fontSourceFolder $fontFile $destPath = Join-Path $fontDestFolder $fontFile $fontName = [System.IO.Path]::GetFileNameWithoutExtension($fontFile) $regName = "$fontName (TrueType)" if (Test-Path $sourcePath) { # Copy font file if (-not (Test-Path $destPath)) { Copy-Item -Path $sourcePath -Destination $destPath -Force Write-Verbose "Copied font: $fontFile" } # Register font in registry try { $regValue = Get-ItemProperty -Path $regPath -Name $regName -ErrorAction SilentlyContinue if (-not $regValue) { New-ItemProperty -Path $regPath -Name $regName -Value $fontFile -PropertyType String -Force | Out-Null Write-Verbose "Registered font: $regName" } } catch { Write-Warning "Failed to register font $fontFile in registry: $_" } } else { Write-Warning "Source font file not found: $sourcePath" } } } TestScript = { $fontSourceFolder = $using:FontsPath $fontDestFolder = "C:\Windows\Fonts" $regPath = "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Fonts" $fontFiles = @( "unifont-15.1.05.ttf", "unifont-all.ttf", "unifont-smooth.ttf", "unifont_csur-15.1.05.ttf", "unifont_jp-15.1.05.ttf", "unifont_upper-15.1.05.ttf" ) $allInstalled = $true foreach ($fontFile in $fontFiles) { $sourcePath = Join-Path $fontSourceFolder $fontFile $destPath = Join-Path $fontDestFolder $fontFile $fontName = [System.IO.Path]::GetFileNameWithoutExtension($fontFile) $regName = "$fontName (TrueType)" # Check if source exists (skip if not available) if (Test-Path $sourcePath) { # Check if font file exists and is registered $fileExists = Test-Path $destPath $regExists = $false try { $regValue = Get-ItemProperty -Path $regPath -Name $regName -ErrorAction SilentlyContinue $regExists = ($regValue -ne $null) } catch { $regExists = $false } if (-not ($fileExists -and $regExists)) { $allInstalled = $false break } } } return $allInstalled } GetScript = { $fontDestFolder = "C:\Windows\Fonts" $installedFonts = Get-ChildItem "$fontDestFolder\unifont*.ttf" -ErrorAction SilentlyContinue return @{Result = "Installed Unifont files: $($installedFonts.Count)"} } } # === APPLICATION CONFIGURATION DEPLOYMENTS === # Deploy FastStone Image Viewer configuration Script DeployFastStoneConfig { SetScript = { $sourcePath = $using:FastStonePath $uid = [System.Environment]::UserName $destPath = "C:\Users\$uid\AppData\Local\FastStone" if (Test-Path $sourcePath) { if (-not (Test-Path $destPath)) { New-Item -ItemType Directory -Path (Split-Path $destPath) -Force | Out-Null } Copy-Item -Path $sourcePath -Destination "C:\Users\$uid\AppData\Local\" -Recurse -Force Write-Verbose "Deployed FastStone configuration" } } TestScript = { $uid = [System.Environment]::UserName $destPath = "C:\Users\$uid\AppData\Local\FastStone" return (Test-Path $destPath) } GetScript = { $uid = [System.Environment]::UserName $destPath = "C:\Users\$uid\AppData\Local\FastStone" return @{ Result = if (Test-Path $destPath) { "Present" } else { "Absent" } } } } # Deploy Firefox policies Script DeployFirefoxPolicies { SetScript = { $sourceFile = $using:FirefoxPath $firefoxPath = "C:\Program Files\Mozilla Firefox" $distributionPath = Join-Path $firefoxPath "distribution" $destinationFile = Join-Path $distributionPath "policies.json" if (Test-Path $sourceFile) { if (-not (Test-Path $distributionPath)) { New-Item -ItemType Directory -Path $distributionPath -Force | Out-Null } Copy-Item -Path $sourceFile -Destination $destinationFile -Force Write-Verbose "Deployed Firefox policies" } } TestScript = { $firefoxPath = "C:\Program Files\Mozilla Firefox" $distributionPath = Join-Path $firefoxPath "distribution" $destinationFile = Join-Path $distributionPath "policies.json" return (Test-Path $destinationFile) } GetScript = { $firefoxPath = "C:\Program Files\Mozilla Firefox" $distributionPath = Join-Path $firefoxPath "distribution" $destinationFile = Join-Path $distributionPath "policies.json" return @{ Result = if (Test-Path $destinationFile) { "Present" } else { "Absent" } } } } # Deploy ShareX configuration Script DeployShareXConfig { SetScript = { $sourceConfigPath = $using:ShareXAppConfigPath $sourceHotkeyPath = $using:ShareXHotkeysPath $shareXSettingsDir = "$env:USERPROFILE\Documents\ShareX" if (-not (Test-Path $shareXSettingsDir)) { New-Item -ItemType Directory -Path $shareXSettingsDir -Force | Out-Null } if (Test-Path $sourceConfigPath) { $destConfigPath = Join-Path $shareXSettingsDir "ApplicationConfig.json" Copy-Item -Path $sourceConfigPath -Destination $destConfigPath -Force Write-Verbose "Deployed ShareX ApplicationConfig.json" } if (Test-Path $sourceHotkeyPath) { $destHotkeyPath = Join-Path $shareXSettingsDir "HotkeysConfig.json" Copy-Item -Path $sourceHotkeyPath -Destination $destHotkeyPath -Force Write-Verbose "Deployed ShareX HotkeysConfig.json" } } TestScript = { $shareXSettingsDir = "$env:USERPROFILE\Documents\ShareX" $configExists = Test-Path (Join-Path $shareXSettingsDir "ApplicationConfig.json") $hotkeyExists = Test-Path (Join-Path $shareXSettingsDir "HotkeysConfig.json") return ($configExists -and $hotkeyExists) } GetScript = { $shareXSettingsDir = "$env:USERPROFILE\Documents\ShareX" $configExists = Test-Path (Join-Path $shareXSettingsDir "ApplicationConfig.json") $hotkeyExists = Test-Path (Join-Path $shareXSettingsDir "HotkeysConfig.json") return @{ Result = if ($configExists -and $hotkeyExists) { "Present" } else { "Absent" } } } } # Deploy PowerToys settings Script DeployPowerToysSettings { SetScript = { $sourceFile = $using:PowerToysPath $powerToysSettingsDir = "$env:LOCALAPPDATA\Microsoft\PowerToys" if (-not (Test-Path $powerToysSettingsDir)) { New-Item -ItemType Directory -Path $powerToysSettingsDir -Force | Out-Null } if (Test-Path $sourceFile) { $destFile = Join-Path $powerToysSettingsDir "settings.ptb" Copy-Item -Path $sourceFile -Destination $destFile -Force Write-Verbose "Deployed PowerToys settings" } } TestScript = { $powerToysSettingsDir = "$env:LOCALAPPDATA\Microsoft\PowerToys" $settingsFile = Join-Path $powerToysSettingsDir "settings.ptb" return (Test-Path $settingsFile) } GetScript = { $powerToysSettingsDir = "$env:LOCALAPPDATA\Microsoft\PowerToys" $settingsFile = Join-Path $powerToysSettingsDir "settings.ptb" return @{ Result = if (Test-Path $settingsFile) { "Present" } else { "Absent" } } } } } } # Generate the MOF file $outputPath = "$env:TEMP\DSC\FileOperations" $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path FileOperations -ScriptDir $scriptDir -OutputPath $outputPath # Apply the configuration Start-DscConfiguration -Path $outputPath -Wait -Verbose -Force