Scripting examples > Job control scripts > Validating an existing job

Validating an existing job

The following sample script will validate an existing job. You will need to modify this script to fit your environment and configuration.

Be sure and expand your screen wide enough so that lines in the script file do not wrap.

 

# Sample script to validate an existing Double-Take job

 

# Specify the variables to be used in the script

 

     # Source server

     $DtSourceName = "alpha"

 

     # Target server and credentials

     $DtTargetName = "beta"

     $DtTargetUserName = "domain\administrator"

     $DtTargetPassword = "password"

 

 

# Import the Double-Take PowerShell module

# This may be \Service\ or \Console\ depending on your installation

Import-Module "C:\Program Files\Vision Solutions\Double-Take\Console\DoubleTake.PowerShell.dll"

 

 

# Create target object

$DtTarget = New-DtServer -Name $DtTargetName -UserName $DtTargetUserName -Password $DtTargetPassword

 

# Find the appropriate job, based on the source server name.

$DtJob = Get-DtJob -ServiceHost $DtTarget | Where-Object { $_.Statistics.CoreConnectionDetails.SourceMachineName -eq $DTSourceName}

 

# Validate the job options.

$DtConfirmation = Confirm-DtJobOptions -ServiceHost $DtTarget -JobId $DtJob.Id -JobOptions $DtJob.Options

 

# Give the validation process time to complete.

while ($true)

{

          sleep 1

          $DtConfirmStatus = Get-DtVerificationStatus -ServiceHost $DtTarget -Token $DtConfirmation

          if ($DtConfirmStatus.Task.Status -eq "Faulted")

          {

                    throw $("Validation failed: {0}" -f $DtConfirmStatus.Task.MessageId)

          }

          if ($DtConfirmStatus.Task.Status -eq "Completed")

          {

                    break

          }

}

$StatusCount=0

$DtConfirmStatus.Steps | ForEach-Object {

          if ($_.Status -eq "Warning" -or $_.Status -eq "Error")

          {

                    $StatusCount++

                    # For each error or warning, display the level and message.

                     Write-Host "$($_.Status) : $($_.MessageKey)"

          }

}

 

# Identify if there were no errors or warnings.

if ($StatusCount -eq 0)

{

          Write-Host "No job validation errors or warnings were detected."

}

 

# Close the connection for the server object

Disconnect-DtServer -ServiceHost $DtTarget

 

If you want to hide your user credentials in your script, use the Windows PowerShell Get-Credential cmdlet. The password will not be visible because Windows stores an encrypted password. See Hiding your password in a PowerShell script for basic details on using this cmdlet. See your Windows PowerShell documentation for detailed instructions.