Step Handlers - Synchronization Service

Does anyone know how to use step handlers? The documentation barely even talks about them and no examples are given.

I would like to take data from srcobj or dstobj and perform actions pre or post run. Is this not doable. In what forms are step handlers useful then?

Parents Reply Children
  • Hello, .

    The only use case for step handlers that I've personally encountered is exactly the scenario that Terrance described above: retrieving or otherwise manipulating the CSV input file (e.g., retrieving or posting to an FTP site, etc) before/after processing.

    Using a bit of code that is something like this:

    $EnableLogging = $true
    $LogPath = "C:\temp\logfile.txt"
    
    function Write-Log() {
        param(
            $text
        )
    
        if ($EnableLogging -ne $true) { 
            return 
        }
    
        $Timestamp = $(Get-Date -Format "dd/MM/yyyy HH:mm:ss.fff").ToString()
        $Text = $Timestamp + "  " + $Text
    
        $null = Add-Content -Path $LogPath -Value $Text
    }
    
    $knownVariables = @(
        "$",
        "?",
        "^",
        "args",
        "ConfirmPreference",
        "ConsoleFileName",
        "DebugPreference",
        "Error",
        "ErrorActionPreference",
        "ErrorView",
        "ExecutionContext",
        "false",
        "FormatEnumerationLimit",
        "HOME",
        "Host",
        "InformationPreference",
        "input",
        "MaximumAliasCount",
        "MaximumDriveCount",
        "MaximumErrorCount",
        "MaximumFunctionCount",
        "MaximumHistoryCount",
        "MaximumVariableCount",
        "MyInvocation",
        "NestedPromptLevel",
        "null",
        "OutputEncoding",
        "PID",
        "PROFILE",
        "ProgressPreference",
        "PSBoundParameters",
        "PSCommandPath",
        "PSCulture",
        "PSDefaultParameterValues",
        "PSEdition",
        "PSEmailServer",
        "PSHOME",
        "PSScriptRoot",
        "PSSessionApplicationName",
        "PSSessionConfigurationName",
        "PSSessionOption",
        "PSUICulture",
        "PSVersionTable",
        "PWD",
        "ShellId",
        "StackTrace",
        "true",
        "VerbosePreference",
        "WarningPreference",
        "WhatIfPreference"
    )
    
    $variables = Get-Variable | ?{$_.Name -notin $knownVariables} | %{$_.Name}
    $null = Write-Log -text ("Variables:`r`n"+($variables -join "`r`n").Trim()+"`r`n")

    You can determine exactly what variables are available - which, as was mentioned above, does not include $srcObj and $dstObj. Here is the list that I get back:

    commonParameters
    dstConnection
    EnableLogging
    knownVariables
    log
    LogPath
    srcConnection

    This step handler should not be confused with connection handlers, which do have access to $srcObj and $dstObj.