Skip to main content
Skip table of contents

Example powershell script for debugging

Description

This is the Windows PowerShell code for a script named display.ps1, which you can insert into any pre-script, post-script, or hook to display a timestamp and the values of the Windows environment variables to a log file located in the C:\TEMP directory on the target host. One purpose of this script, if inserted into every hook, is to better understand the order of operations within the Delphix Engine. It would also help you understand the duration of those operations.

Of course, this basic script is intended to be augmented for more custom diagnostic output, as desired.

Disclaimer

This sample code is offered for illustration purposes only, and does not carry any warranty or guarantee. Employing copies of this code, in whole or in part, indicates acceptance of all risks.

Source code for script

Downloadable copy display.ps1

CODE
#================================================================================
#  File:      display.ps1
#  Type:      Powershell script
#  Date:      04-Nov 2016
#  Author:    Delphix
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#
#  Copyright (c) 2016 by Delphix. All rights reserved.
# 
#  Description:
#
#    Windows Powershell script intended to be used for debugging purposes, by
#    logging timestamped variable values with the name of the hook from which
#    it was called to an output file on the user's desktop.
#
#  Usage:
#
#    display.ps1 <hook-name>
#
#    where:
#        <hook-name>    the name of the dSource or VDB hook from
#                which this script is called:
#                    For dSources...
#                        Pre-Sync, Post-Sync
#                    For VDBs...
#                        Configure-Clone,
#                        Pre-Refresh, Post-Refresh,
#                        Pre-Rewind, Post-Rewind,
#                        Pre-Snapshot, Post-Snapshot
#
#    If the hook-name does not have the correct text, then the script will not
#    not recognize it and will emit an error message.
#
#  Modifications:
#================================================================================
param([string]$hookName)
#
#--------------------------------------------------------------------------------
# Set up variables for use within the script...
#--------------------------------------------------------------------------------
$outDir = "C:\TEMP"
$timeStamp = Get-Date -format o
#
#--------------------------------------------------------------------------------
# Output values for Windows environment variables set with hook session by the
# Delphix virtualization engine...
#
# If the name of the hook implies a VDB hook, then output the values for the
# relevant variables...
#--------------------------------------------------------------------------------
if ( ( $hookName.ToUpper() -eq "CONFIGURE-CLONE" ) -or
     ( $hookName.ToUpper() -eq "PRE-REFRESH" ) -or
     ( $hookName.ToUpper() -eq "POST-REFRESH" ) -or
     ( $hookName.ToUpper() -eq "PRE-REWIND" ) -or
     ( $hookName.ToUpper() -eq "POST-REWIND" ) -or
     ( $hookName.ToUpper() -eq "PRE-SNAPSHOT" ) -or
     ( $hookName.ToUpper() -eq "POST-SNAPSHOT" ) ) {
    $outFile = $outDir + "\HOOK_OUTPUT_" + $env:VDB_DATABASE_NAME + ".TXT"
    $timeStamp + "|" + $hookName + ": VDB_INSTANCE_HOST is '" + $env:VDB_INSTANCE_HOST + "'" | Out-File -FilePath $outFile -Append
    $timeStamp + "|" + $hookName + ": VDB_INSTANCE_PORT is '" + $env:VDB_INSTANCE_PORT + "'" | Out-File -FilePath $outFile -Append
    $timeStamp + "|" + $hookName + ": VDB_INSTANCE_NAME is '" + $env:VDB_INSTANCE_NAME + "'" | Out-File -FilePath $outFile -Append
    $timeStamp + "|" + $hookName + ": VDB_DATABASE_NAME is '" + $env:VDB_DATABASE_NAME + "'" | Out-File -FilePath $outFile -Append
} else {
    #
    #------------------------------------------------------------------------
    # If the name of the hook implies a dSource hook, then output the values
    # for the relevant variables...
    #------------------------------------------------------------------------
    if ( ( $hookName.ToUpper() -eq "PRE-SYNC" ) -or
         ( $hookName.ToUpper() -eq "PRE-SYNC" ) ) {
        $outFile = $outDir + "\HOOK_OUTPUT_" + $env:SOURCE_DATABASE_NAME + ".TXT"
        $timeStamp + "|" + $hookName + ": SOURCE_INSTANCE_HOST is '" + $env:SOURCE_INSTANCE_HOST + "'" | Out-File -FilePath $outFile -Append
        $timeStamp + "|" + $hookName + ": SOURCE_INSTANCE_PORT is '" + $env:SOURCE_INSTANCE_PORT + "'" | Out-File -FilePath $outFile -Append
        $timeStamp + "|" + $hookName + ": SOURCE_INSTANCE_NAME is '" + $env:SOURCE_INSTANCE_NAME + "'" | Out-File -FilePath $outFile -Append
        $timeStamp + "|" + $hookName + ": SOURCE_DATABASE_NAME is '" + $env:SOURCE_DATABASE_NAME + "'" | Out-File -FilePath $outFile -Append
    } else {
        #
        #----------------------------------------------------------------
        # If the name of the hook is not recognized, then output an error
        # message to that effect...
        #----------------------------------------------------------------
        $outFile = $outDir + "\HOOK_OUTPUT_UNKNOWN.TXT"
        $timeStamp + ": unknown hook name '" + $hookName + "'" | Out-File -FilePath $outFile -Append
    }
}

Output

The name of the output file created by this script includes the name of the database, so all output from all hooks associated with this database name will be appended to the same file.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.