# # AEM_simple_gettaskdetails.ps - Hein van den Heuvel - August 2017 # PowerShell - Attunity Enterprise Manager dotnet RestAPI example # # Please adapt defaults for parameters to actual values, notably $AemServer # param( [string]$TaskName = 'No Task Name' ,[string]$RepServer = 'localhost' ,[string]$AemServer = 'localhost' ,[string]$AemURL = "https://" + $AemServer + "/attunityenterprisemanager" ,[string]$AemUserName = $env:UserDomain + '\' + $env:UserName ,[string]$AemCredentialFile = "AEMCredentials.txt" ,[System.Management.Automation.PSCredential]$Credential ,[switch]$csv ) # # Locate and Map RestAPI library files AemRestClient.dll and helper Newtonsoft.Json # if ( $PSScriptRoot ) { $root = $PSScriptRoot } else { $root = '.' } # in case running as cut & paste $file = $root + '\AemRestClient.dll' if (-not (Test-Path $file) ) { "Please provide $file and Newtonsoft.Json from Attunity\Enterprise Manager\clients\dotnet"; return } Import-Module ( $root + '\AemRestClient.dll' ) # # Locate and obtain credentials, if not provided as argument using: # $credential = Get-Credential -Credential $AemUserName # if (-not $credential) { # Use existing credential? $file = $root + '\' + $AemCredentialFile if (Test-Path $file) { # Is there a credential file already ? $password = Get-Content $file | ConvertTo-SecureString $credential = New-Object System.Management.Automation.PSCredential($AemUserName,$password) } else { # Create get credential and store in file. $credential = Get-Credential -Credential $AemUserName $credential.Password | ConvertFrom-SecureString | Set-Content $file } } # # Ready to connect. # $client = New-Object Attunity.Aem.RestClient.AemRestClient($Credential, $AemURL) if (-not $client) { return } # Did we get a useable client object ? if ($csv) { # Select formatting option. $task_format = "{0},{6},{7},{1},{2},{3},{4},{5}" } else { $task_format = "{0,19} {1,9} {2,9} {3,9} {4,9} {5}" } Write-Output ($task_format -f "Time", "Source", "Latency", "Incoming", "Applying", "Ins/Upd/Del/DDL","Server","Task" ) if (-not $csv) { Write-Output ($task_format -f "-------------------", "--------", "--------", "--------", "--------", "---------------","","") } # # Main loop # while ( 1 ) { $now = (Get-Date -Format "yyyy-MM-dd HH:mm:ss") $task = $client.AemGetTaskDetails($RepServer,$taskname) if (-not $task) { return } # Hopefully the error from the RestAPI call is clear enough. $state = $task.Task.State if ($state -ne "RUNNING") { Write-Output ($task_format -f $now, $task.Task.State, '', '', '', '', $RepServer, $taskname) } else { $x = $task.Task.CdcTransactionsCounters # 'short name' $i = $x.IncomingAccumulatedChangesInMemoryCount + $x.IncomingAccumulatedChangesOnDiskCount $a = $x.IncomingApplyingChangesInMemoryCount + $x.IncomingApplyingChangesOnDiskCount $x = $task.Task.CdcEventCounters # re-use short name $IUDd = '' + $x.AppliedInsertCount + '/' + $x.AppliedUpdateCount + '/' + $x.AppliedDeleteCount +'/' + $x.AppliedDdlCount Write-Output ($task_format -f $now, $task.Task.CdcLatency.SourceLatency, $task.Task.CdcLatency.TotalLatency, $i, $a, $IUDd, $RepServer, $taskname ) } sleep 5 # or as long as you please. }