Friday, July 28, 2017

How to inventory all Repliweb Jobs

Recently got an opportunity to explore Attunity's Repliweb, a content deployment tool which can deploy packages across multiple targets from a source code repository. Although the GUI tool provides options to manage the deployment and their resulting logs, it lacks options to export the inventory of all jobs.

But it exposes API via PowerShell to take the inventory. As I was not able to find such script anywhere, thought of sharing it via this post.

Below script creates a csv file in the current directory which will contain all jobs along with their status and edges list.

<#
.SYNOPSIS
Fetches all jobs from Repliweb center
.DESCRIPTION
Fetches all jobs from Repliweb center
.PARAMETER username
A repliweb username
.PARAMETER password
A repliweb password for the username provided
.PARAMETER domain
Domain name for the username
.EXAMPLE
.\fetchJobs.ps1 -username "JohnDoe" -password "secretword" -domain "contoso"
.NOTES
Run this script in a repliweb center's powershell console as administrator.
#>


[CmdletBinding()]
Param(
[parameter(mandatory=$true)]
[string] $username,

[parameter(mandatory=$true)]
[string] $password,

[parameter(mandatory=$true)]
[string] $domain
    )

if ((Get-PSSnapin -Name r1_ps_api -ErrorAction SilentlyContinue) -eq $null )
  {  
      Add-PsSnapin r1_ps_api
  }
##-----------------------------------------------------------------------

## Global Constants
$fileName="$($env:Computername)_$(get-date -format `"yyyyMMdd_hhmmsstt`").txt"
$currentDir=Split-Path $script:MyInvocation.MyCommand.Path
$logfile =  join-path $currentDir $fileName

##-----------------------------------------------------------------------
##-----------------------------------------------------------------------
## Global functions:
function write-log([string[]]$logline)
{
  $logline | out-file -Filepath $logfile -append
}
##-----------------------------------------------------------------------

$R1Session=Get-R1Session
$pass=$R1Session.ScramblePassword($password)
$R1Session.Center="localhost"
$R1Session.User=$username
$R1Session.ScrambledPassword=$pass
$R1Session.Domain=$domain
#$R1Session.QueryFilter.JobType= "R1_DISTRIBUTION"
$connected=$R1Session.Connect()
$jobs=$R1Session.GetJobList()
write-host " Session established and jobs retrieved"
$header="ID,Name,Type,State,SourceDirectory,Stage,Edges"
write-log $header
foreach($job in $jobs)
{
$edges=''
    #job.info = DistributionInfo or MSIInfo
foreach($edge in $job.info.edgesNames)
{
$edges+= $edge + ";"
}  
 $logline=$job.Id + "," + $job.Name + "," + $job.Type + "," + $job.State + "," + $job.SourceDirectory + "," + $job.Stage + "," + $edges
write-log $logline
}
write-host " Export process completed."

1 comment:

Anonymous said...

What editing do I need to do to get this to work --- the user, pw, and domain for example(?)