Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Delphix Web API – PowerShell Run Masking Job

Posted on April 19, 2018 By David Kittell

Take note of the Global Variables $BaseURL and $LogFilePath, make sure you set them to your values.

The idea for this script is to run this as part of a database restore/migration. Drop all access to the database to do the restore/migration, then run the script for Delphix, and then restore all access.

<#
.SYNOPSIS
Delphix - Run Masking Job

.DESCRIPTION
This script will kick off a masking job within Delphix

.EXAMPLE
.\Delphix-RunJob.ps1 -DelphixApplication Core -DelphixJob 31 -DelphixUser dkittell

#>

Param(
    [Parameter(
        Position=0,
        Mandatory = $True,
        HelpMessage="What Delphix Application?",
        valueFromPipeline=$true)]
    [String] $DelphixApplication,

    [Parameter(
        Position=1,
        Mandatory = $True,
        HelpMessage="What Delphix Job?",
        valueFromPipeline=$true)]
    [String] $DelphixJob,
    
    [Parameter(
        Position=2,
        Mandatory = $True,
        HelpMessage="What Delphix User Name?",
        valueFromPipeline=$true)]    
    [String] $DelphixUser,
    
    [Parameter(
        Position=3,
        Mandatory = $True,
        HelpMessage="What Delphix User Password?",
        valueFromPipeline=$true)]    
    [Security.SecureString] $DelphixPassword
 
)

# Global Variables - Start
$BaseURL = "http://192.168.1.2:123/dmsuite/apiV4/"
$LogFilePath = "c:\"
# Global Variables - Done

#Get Token - Start
$tokenReq = try {
    # Token Variables - Start
    Write-Output $DelphixUser
    $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($DelphixPassword)
    $UnsecurePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
    $url = $BaseURL + "login?user=$($DelphixUser)&password=$($UnsecurePassword)"
    #Write-Output $url
    #exit
    # Token Variables - Done
    Invoke-WebRequest -Uri $url -Method GET
}
catch {
    Write-Output "ERROR"
    write-Output "ERROR" | Out-File "${$LogFilePath}DelphixStatus_${DelphixApplication}_${DelphixJob}.txt"
    exit
}

$token = $tokenReq.Headers.auth_token
Write-Output $token
#Get Token - Done

# Run Masking Job - Start
$RunReq = try {
    # RunReq Variables - Start
    $url = $BaseURL + "applications/$DelphixApplication/maskingjobs/$DelphixJob/run"
    $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
    $headers = @{}
    $headers.Add("Content-Type","application/xml" )
    $headers.Add("auth_token",$token )
    # RunReq Variables - Done

    Invoke-WebRequest -Uri $url -Method POST -Headers $headers -Body "<MaskingsRequest/>"
}
catch {
   write-Output "ERROR" | Out-File "${$LogFilePath}DelphixStatus_${DelphixApplication}_${DelphixJob}.txt"    
}

Write-Output $RunReq
# Run Masking Job - Done

# Get Masking Job Status - Start
function Get-JobStatus{
    $RunReq = try {
        # RunReq Variables - Start
        $url = $BaseURL + "applications/$DelphixApplication/maskingjobs/$DelphixJob/results"
        $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
        $headers = @{}
        $headers.Add("Content-Type","application/xml" )
        $headers.Add("auth_token",$token )
    
 
    # RunReq Variables - Done
    Invoke-WebRequest -Uri $url -Method GET -Headers $headers 
}
catch {
   write-Output "ERROR" | Out-File "${$LogFilePath}DelphixStatus_${DelphixApplication}_${DelphixJob}.txt"
}
 
$xml = [xml]($(write-output $RunReq.Content))
return $xml.MaskingsResponse.Maskings.Masking.Status
}
# Get Masking Job Status - Done

$a = 1
DO
    {
        $status = Get-JobStatus

        switch ($status)
            {
                "RUNNING" {
                    #Write-Output $status
                    write-Output "Running..."
                }
                "SUCCESS" {
                    Write-Output $status
                    write-Output "Success" | Out-File "${$LogFilePath}DelphixStatus_${DelphixApplication}_${DelphixJob}.txt"
                    $a = 2
                }
                "ERROR" {
                    Write-Output $status
                    write-Output "Error" | Out-File "${$LogFilePath}DelphixStatus_${DelphixApplication}_${DelphixJob}.txt"
                    $a = 2
                }
                default {
                    Write-Output $status
                    Write-Output "Not running"
                    write-Output $status | Out-File "${$LogFilePath}DelphixStatus_${DelphixApplication}_${DelphixJob}.txt"
                    $a = 2
                }
            }
    }
WHILE ($a -ne 2)

All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code Delphix PowerShell SQL WebAPI

Post navigation

Previous post
Next post

Related Posts

Mac OSX Terminal – Turn off system sleep

Posted on April 4, 2016April 4, 2016

If you use a Mac whether true server or a Mac Mini for a server this script below is very helpful to prevent the Mac from falling asleep and preventing the machine from being a server. # Disable Computer Sleep sudo systemsetup -setcomputersleep Off sudo systemsetup -getcomputersleep # Disable Computer…

Read More

PowerShell – Clean Windows 10

Posted on March 9, 2016April 2, 2022

Work In Progress This will remove some of the default apps along with a couple other fun features to come. clear # Many of the below items are from #https://tweakhound.com/2015/12/09/tweaking-windows-10/ #cd ~\Desktop #mkdir "God Mode.{ED7BA470-8E54-465E-825C-99712043E01C}" function Change-Service ($servicename, $serviceaction, $servicestatuptype) { if (Get-Service $servicename -ErrorAction SilentlyContinue) { $ServiceDetail=$(Get-Service -Displayname $servicename)…

Read More

Ektron – Category Template

Posted on October 31, 2014October 26, 2015

<%@ Page Language="C#" MasterPageFile="~/masterpages/content.master" AutoEventWireup="true" CodeFile="boardlanding.aspx.cs" Inherits="templates_categorylanding" Title="Category Landing Page" %> <%@ Register Assembly="Ektron.Cms.Controls" Namespace="Ektron.Cms.Controls" TagPrefix="CMS" %> <%@ Register Src="~/usercontrols/breadcrumb.ascx" TagName="Breadcrumb" TagPrefix="uc" %> <asp:Content ID="Header" ContentPlaceHolderID="ContentHeaderContentPlaceHolder" runat="server"> <!– categorylanding –> <img class="banner" alt="banner" src="/img/banner_01.jpg"> </asp:Content> <asp:Content ID="Left" ContentPlaceHolderID="LeftContentPlaceHolder" runat="Server"> <div id="crumbs"> <uc:Breadcrumb ID="breadcrumbControl" runat="server" /> </div> <img class="divider upper" alt=""…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes