#Requires -Version 5.1 [CmdletBinding()] param( [string]$BaseImagePath = (Join-Path $env:ProgramData 'SGU\Branding\darkblue.jpg'), [string]$FontsPath = (Join-Path $env:ProgramData 'SGU\Branding\fonts'), [string]$OutputPath, [string]$DisplayName, [string]$ComputerName = $env:COMPUTERNAME, [string]$Location, [string]$OrganizationalUnit, [ValidateSet('Male', 'Female')] [string]$Gender, [ValidateRange(640, 16384)] [int]$CanvasWidth, [ValidateRange(480, 16384)] [int]$CanvasHeight, [switch]$SkipDirectoryLookup, [switch]$SkipApply ) $ErrorActionPreference = 'Stop' $script:LogPath = Join-Path $env:LOCALAPPDATA 'SGU\Logs\welcome-wallpaper.log' Add-Type -AssemblyName System.Drawing function Write-WelcomeLog { param([Parameter(Mandatory)][string]$Message) try { $logDirectory = Split-Path $script:LogPath -Parent New-Item -ItemType Directory -Path $logDirectory -Force | Out-Null Add-Content -LiteralPath $script:LogPath ` -Value ('{0:o} {1}' -f (Get-Date), $Message) ` -Encoding UTF8 } catch { # The wallpaper must still be generated when logging is unavailable. } } function ConvertTo-LdapFilterValue { param([Parameter(Mandatory)][string]$Value) return $Value.Replace('\', '\5c').Replace('*', '\2a').Replace('(', '\28').Replace(')', '\29').Replace(([string][char]0), '\00') } function ConvertFrom-LdapRdnValue { param([Parameter(Mandatory)][string]$Value) $decoded = [Text.RegularExpressions.Regex]::Replace( $Value, '\\([0-9A-Fa-f]{2})', { param($match) [char][Convert]::ToByte($match.Groups[1].Value, 16) }) return $decoded.Replace('\,', ',').Replace('\+', '+').Replace('\=', '=').Replace('\\', '\') } function Get-ImmediateOrganizationalUnit { param([string]$DistinguishedName) if (-not $DistinguishedName) { return $null } $parts = [Text.RegularExpressions.Regex]::Split($DistinguishedName, '(?