param( [Parameter(Mandatory=$true)] [string]$Identity, [Parameter(Mandatory=$true)] [string]$TemplatePath # Path to the HTML template file ) # Import admin credentials $serverAddress = Get-Content -Path ".\DefaultServer.txt" $credential = Import-Clixml -Path .\AdminCredential.xml # Establish session with Exchange Server $ExchSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "http://$serverAddress/PowerShell/" -Authentication Kerberos -Credential $credential Import-PSSession $ExchSession -DisableNameChecking -AllowClobber # Retrieve user's details $userDetails = Get-User -Identity $Identity $mailboxDetails = Get-Mailbox -Identity $Identity # Extract user information $fullName = $userDetails.DisplayName $jobTitle = $userDetails.Title $address = "$($userDetails.StreetAddress), $($userDetails.City), $($userDetails.StateOrProvince), $($userDetails.PostalCode)" $phoneNumber = $userDetails.TelephoneNumber $mobileNumber = $userDetails.MobilePhone $email = $mailboxDetails.PrimarySmtpAddress # Load the HTML template $templateContent = Get-Content -Path $TemplatePath -Raw # Replace placeholders with actual user details $templateContent = $templateContent -replace "{{FullName}}", $fullName $templateContent = $templateContent -replace "{{JobTitle}}", $jobTitle $templateContent = $templateContent -replace "{{Address}}", $address $templateContent = $templateContent -replace "{{PhoneNumber}}", $phoneNumber $templateContent = $templateContent -replace "{{MobileNumber}}", $mobileNumber $templateContent = $templateContent -replace "{{Email}}", $email # Update user's email signature Set-MailboxMessageConfiguration -Identity $Identity -SignatureHtml $templateContent # Enable the automatic inclusion of the signature Set-MailboxMessageConfiguration -Identity $Identity -AutoAddSignature $true Write-Host "Email signature updated successfully!" # Clean up the remote PowerShell session Remove-PSSession $ExchSession