[CmdletBinding()]param ( [Parameter(ValueFromPipeline=$true)] [string] $B64Input)$ErrorActionPreference ="Stop"$DebugPreference ='Continue'functionConvertFrom-B64 {param ( [string] $B64String )try { $Json = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($B64String)) $Output = $Json |ConvertFrom-Json }catch {Write-Error"Failed to convert Base64 string: $B64String" }return $Output}# The JSON data is passed to the Gateway as a Base64 encoded string.$Params =ConvertFrom-B64-B64String $B64InputWrite-Debug"Running Post-Rotation Script on: $($Params.userRecordUid)"# Convert the attached Resource Records from Base64 encoded JSON string and find the # Admin Record we need to update the Service's `Log On As` property by filtering by the # Admin Record's UID.$ResourceCredentials =ConvertFrom-B64-B64 $Params.records$AdminRecord = $ResourceCredentials |Where-Object { $_.uid-eq'<Admin Record UID>' }$AdminUserName ="$($AdminRecord.login)@$($AdminRecord.domainName)"$ScheduledTaskName ='<Scheduled Task Name>'Write-Debug"Updating Scheduled Task: $ScheduledTaskName"schtasks /change /tn $ScheduledTaskName /s '<Target Machine>' /u $AdminUserName /p $AdminRecord.password /ru $Params.user /rp $Params.newPassword
if( $LastExitCode-ne0 ) { exit$LastExitCode}