Skip to content

PowerShell

The SQDR PowerShell module scripts what you do in the Data Replicator Manager: run and stop replications, pause and resume incremental groups, export and import subscriptions, read statistics and change service properties. Use it for scheduled jobs, deployments from test to production, and monitoring scripts.

The module is a set of cmdlets in SQDRPowershell.dll, installed with the Replicator Service. Each cmdlet calls the Replicator Service directly, on its PowerShell port (7738 by default).

To script Capture Agents (create, start, stop and delete them), see Script Capture Agents with PowerShell.

Install location

Platform Module Requirements
Windows C:\Program Files\StarQuest\SQDR\Tools\SQDRPowershell.dll Windows PowerShell 5.1 or later
Docker container /opt/StarQuest/sqdr/tools/SQDRPowershell.dll PowerShell (pwsh) is installed in the container

Load the module

# Windows
Import-Module "C:\Program Files\StarQuest\SQDR\Tools\SQDRPowershell.dll"

# Docker container (in pwsh)
Import-Module /opt/StarQuest/sqdr/tools/SQDRPowershell.dll

# List the cmdlets
Get-Command -Module SQDRPowershell

The module has no help text: Get-Help shows only a cmdlet's syntax. This page says what each one does.

Connect to the Replicator Service

Every cmdlet has a -ConnStr parameter, the address of the Replicator Service's PowerShell port.

Form When
(omitted) The default, 127.0.0.1:7738: the Replicator Service on the same computer.
host:port Another service or port. If the port is left out, :7738 is added.
user:password@host:port When Role Based Access Control is on. Encode special characters in the user or password as in a URL, for example @ as %40.

The PowerShell port. The cmdlets use the service's second listener, grpcTransADDRPORT, not the Data Replicator Manager's port (7737).

  • Windows: the port accepts local connections only (127.0.0.1:7738), so run scripts on the Replicator Service's computer. To allow remote scripts, set grpcTransADDRPORT to 0.0.0.0:7738, restart the service and open the port in the firewall.
  • Docker: the service listens on port 7738 on all interfaces. Run scripts inside the container, or from another computer if the container's port 7738 is published.

With Role Based Access Control on, the cmdlets have the permissions of the user in -ConnStr. See Access control.

Use the cmdlets

  • Name the parameters (-GroupName MYGROUP) rather than relying on their position, and pass values as arguments: the cmdlets don't take pipeline input.
  • Boolean parameters take $true or $false (or 1 and 0).
  • JSON files. Cmdlets that read or write definitions use JSON files. Give absolute paths: a relative path is resolved against the process's starting folder, not the current PowerShell location.
  • Output. The Show-, Get- and Read- cmdlets return objects, one per row, that you can pipe to Format-Table, Where-Object or Export-Csv. Most also take -JsonFileOut <file>, which writes the result as JSON to the file instead.
  • Errors are terminating errors with the service's message, so use try / catch in scripts.
  • Validation. With -Validate $true (the default where the cmdlet has it), the Replicator Service saves a subscription only when validation reports nothing: an error, a warning or a note stops the save, as in the Data Replicator Manager, where you confirm the messages. New-, Set-, Copy-, Convert- and Import-Subscription and Import-Subscriptions write the warnings and notes to the warning stream, then raise an error saying the subscription was NOT saved, with the messages that stopped it. If there were only warnings, check them, then run the cmdlet again with -Validate $false to save despite them. -Validate $false never saves past an error. New-Subscription and Import-Subscriptions raise a non-terminating error for each subscription and go on with the others; the other cmdlets stop.
  • The same rules as the Data Replicator Manager. The Replicator Service checks every save, whichever client sends it: an incremental subscription uses its group's source and destination, a group holds one subscription per source table, and criteria without WHERE get it added. See also Move-Subscription, Copy-Subscription and Set-Group below.
  • Source and destination types. -SrcDestType takes 1 for a source, 2 for a destination, 3 for a staging database.

Examples

Import-Module "C:\Program Files\StarQuest\SQDR\Tools\SQDRPowershell.dll"
$c = "127.0.0.1:7738"              # with Role Based Access Control: "user:[email protected]:7738"

Export and import subscriptions

Copy the subscriptions of a group from a test service to a production service. The target group must exist.

# On the test service: all subscriptions of a group, or one subscription
Export-Subscriptions -ConnStr $c -GroupName SALES_GROUP -JsonFileOut C:\temp\sales-subs.json
Export-Subscription  -ConnStr $c -SourceName SALES_SRC -SubscriptionName ORDERS -JsonFileOut C:\temp\orders.json

# On the production service: create them in a group, validating each one
Import-Subscriptions -ConnStr $c -JsonFile C:\temp\sales-subs.json -ToGroupName SALES_GROUP -Validate $true
Import-Subscription  -ConnStr $c -JsonFile C:\temp\orders.json -ToGroupName SALES_GROUP

The import cmdlets return each subscription's validation messages; a subscription that validation stopped also raises an error (see Use the cmdlets). Importing into an incremental group refuses a subscription whose source table another member already replicates ("A subscription to the source table '...' already exists in the group '...'"); a subscription of the same name replaces that member.

Add many tables to a group

New-Subscription creates one subscription per source table with the defaults the Subscription Wizard would use, so one loop adds a list of tables to a group. Set the group's defaults first: for an incremental group, its Subscription Wizard Defaults; for a snapshot group, its Advanced tab (see Group properties).

$tables = "ORDERS", "ORDER_LINES", "CUSTOMERS"

# Incremental group: the source, destination and schemas come from the group
$tables | ForEach-Object { New-Subscription -ConnStr $c -GroupName SALES_GROUP -SourceTable $_ -SourceSchema SALES }

# Snapshot group: name the source and destination
$tables | ForEach-Object { New-Subscription -ConnStr $c -GroupName SALES_SNAP -SourceTable $_ -SourceSchema SALES `
    -SourceName SALES_SRC -DestinationName SALES_DEST }

Each subscription gets:

  • the Destination DDL Option, Rows at Baseline and Baseline Type of the group's defaults, unless you give -DropType or -ReplicationType;
  • the destination database and schema you give with -DestinationCatalog and -DestinationSchema; otherwise the group's defaults when it goes to the group's destination, else the destination's own defaults. When the destination uses a database or schema in its table names and none can be found, the subscription isn't saved;
  • the source table's name as the destination table name, unless you give -DestinationTable.

A table that fails validation raises an error for that table, and the loop goes on (see Use the cmdlets).

Run a subscription or a group

# One subscription (for an incremental subscription, this runs a new baseline)
Start-Replication -ConnStr $c -SourceName SALES_SRC -SubscriptionName ORDERS

# A whole group: leave out -SourceName and pass the group name as -SubscriptionName
Start-Replication -ConnStr $c -SubscriptionName SALES_GROUP

# Is it still running? Stop it
Test-ReplicationIsRunning -ConnStr $c -SourceName SALES_SRC -SubscriptionName ORDERS
Stop-Replication -ConnStr $c -SubscriptionName SALES_GROUP

Pause and resume an incremental group

Enable-IncrementalPolling -ConnStr $c -GroupName SALES_GROUP -EnablePolling $false   # pause
Enable-IncrementalPolling -ConnStr $c -GroupName SALES_GROUP -EnablePolling $true    # resume

# SQL wildcards work in the group name: pause every group whose name starts with SALES
Enable-IncrementalPolling -ConnStr $c -GroupName 'SALES%' -EnablePolling $false

# All incremental groups of a source, or of a destination
Enable-SourcePoll  -ConnStr $c -SrcDestName SALES_SRC  -EnablePolling $false
Resume-Destination -ConnStr $c -SrcDestName SALES_DEST -EnablePolling $true

List statistics

Show-Groups -ConnStr $c | Format-Table
Show-GroupStatistics -ConnStr $c -GroupName SALES_GROUP | Format-Table
Show-SubscriptionStatistics -ConnStr $c -SourceName SALES_SRC -SubscriptionName ORDERS `
    -JsonFileOut C:\temp\orders-stats.json

Cmdlets

-ConnStr and -JsonFileOut are left out of the parameter lists. Optional parameters are in [brackets], with their default when there is one.

Sources and destinations

Cmdlet Parameters What it does
Show-SrcDest -SrcDestType Lists the sources, destinations or staging databases.
Show-SrcDestExtended -SrcDestName Shows a source's or destination's details and IP addresses.
Show-SrcDestData -SrcDestType, -SrcDestName Shows the stored definition of a source or destination.
Set-SrcDest -JsonFile Creates or updates a source or destination from a JSON definition.
Remove-SrcDest -SrcDestType, -SrcDestName Deletes a source or destination.
Show-DBInfo -SrcDestType, -SrcDestName, [-GetIRInfo] Shows database information, and for a source the incremental (Stelo Capture) information.
Test-Source -DsnName, -UserID, -Password, [-ConnectionStringOverride], -UseIntegratedSecurity Tests a source connection.
Test-Destination Same as Test-Source, [-Streaming = $false] Tests a destination connection.
Show-ConnectorsMetadata -SrcDestType Lists the available connector types.
Show-ConnectorTemplates [-DbType], [-DriverName], [-DbName] Lists connection string templates.
Enable-SourcePoll -SrcDestName, -EnablePolling Pauses ($false) or resumes ($true) every incremental group of a source.
Resume-Destination -SrcDestName, -EnablePolling Pauses ($false) or resumes ($true) every incremental group of a destination.
Unregister-Groups -SrcDestName Stops the incremental groups of a source and removes their registration with the Capture Agent.
Invoke-SourceReplay -SrcDestName, -NewPosition, -IsTX Replays the changes of a source's incremental groups from a position. Use it only with Stelo Support.
Restore-DestReplay -SrcDestName, -NewPosition, -IsTX The same for the incremental groups of a destination.

Subscriptions

Cmdlet Parameters What it does
Show-Subscriptions -SourceName, [-JsonFilterFile] Lists a source's subscriptions, optionally filtered.
Show-Subscription -SourceName, -SubscriptionName, [-JsonDataColumnsFileOut, -JsonDataIndexesFileOut, -JsonDataConstraintsFileOut, -JsonDataSchedulesFileOut] Shows a subscription with its columns, indexes, constraints and schedules; the file parameters write each part to a JSON file.
Set-Subscription -JsonFile, -JsonColumnsFile, -JsonIndexesFile, -JsonConstraintsFile, -JsonSchedulesFile, [-Validate = $true] Creates or updates a subscription from the five files that Show-Subscription writes. Returns the validation messages.
Show-DefaultSubscription -JsonFile Shows the columns the service would propose for a new subscription.
New-Subscription -GroupName, -SourceTable, [-SourceSchema, -SourceCatalog, -SourceName, -SubscriptionName, -DestinationName, -DestinationCatalog, -DestinationSchema, -DestinationTable, -DropType, -ReplicationType, -Criteria, -Validate = $true, -JsonFileOut] Creates a subscription of a source table in a group, with the default column mapping and the group's defaults: its source, destination, schemas and default derived columns. For a snapshot group, give -SourceName and -DestinationName. Without -DropType or -ReplicationType, the subscription gets the group's Subscription Wizard Defaults (incremental group) or Subscription Defaults (snapshot group); see Add many tables to a group.
Export-Subscription -SourceName, -SubscriptionName, -JsonFileOut Writes a subscription to a JSON file.
Export-Subscriptions -GroupName, -JsonFileOut Writes all subscriptions of a group to a JSON file.
Import-Subscription -JsonFile, -ToGroupName, [-Validate = $true] Creates a subscription from an exported file, in a group.
Import-Subscriptions -JsonFile, -ToGroupName, -Validate Creates the subscriptions of an exported file, in a group.
Remove-Subscription -SourceName, -SubscriptionName, [-GroupName] Deletes a subscription.
Rename-Subscription -SourceName, -SubscriptionName, -NewSubscriptionName Renames a subscription.
Move-Subscription -SourceName, -SubscriptionName, -ToGroupName Moves an incremental subscription to another incremental group with the same source and destination and no subscription for the same source table. Pause the target group first.
Copy-Subscription -FromSourceName, -FromSubscriptionName, -ToGroupName, -MemberQualifier, -MemberQualifierPosition, -Validate, -ChangeSubscriptionName, -ChangeDestinationTableName, -MemberQualifierOld Copies a member to another group, changing a qualifier in its names. The target group's source and destination must be of the same database types, and it must not have a subscription for the same source table. All parameters are required.
Convert-Subscription Same as Copy-Subscription, without -From... and -ToGroupName Changes a qualifier in a subscription's names.
Show-IRMetaData -SourceName, -SubscriptionName Shows the incremental column information of a subscription.
Confirm-WhereClause -SrcDestName, [-SourceTableQualifier], -SourceTableOwner, -SourceTableName, [-SourceTableMember], [-WhereClause] Checks a criteria and returns how many rows it selects.

Groups

Cmdlet Parameters What it does
Show-Groups — Lists the groups.
Get-Group -GroupName, [-JsonDataMembersFileOut, -JsonDataSchedulesFileOut] Shows a group with its members and schedules.
Show-GroupMembers -GroupName, [-JsonFilterFile] Lists a group's members.
Set-Group -JsonFile, -JsonMembersFile, -JsonSchedulesFile Creates or updates a group from JSON files. For an existing incremental group, the members file can only change their run order.
Set-GroupMembers -GroupName, -JsonFile Replaces the members of a snapshot group.
Copy-Group -OldGroupName, -NewGroupName Creates a group with the same properties and schedules, without members.
Rename-Group -GroupName, -NewGroupName Renames a group.
Remove-Group -GroupName, -DeleteSubscriptions Deletes a group, and optionally its subscriptions.
Remove-GroupMember -GroupName, -SourceName, -SubscriptionName Removes a member from a group.
Skip-GroupStartOffset -GroupName, -Offset Sets the member at which the next group run starts.

Running replications

Cmdlet Parameters What it does
Start-Replication [-SourceName], -SubscriptionName Runs a subscription. Without -SourceName, runs the group named in -SubscriptionName.
Stop-Replication [-SourceName], -SubscriptionName Stops a running subscription, or a group without -SourceName.
Test-ReplicationIsRunning -SourceName, -SubscriptionName Returns whether the subscription is running.
Sync-IncrementalGroup -GroupName, [-Force = $false] Runs an incremental group: baselines the members that need one; with -Force $true, forces them.
Enable-IncrementalPolling -GroupName, -EnablePolling Pauses ($false) or resumes ($true) an incremental group. % wildcards allowed.
Connect-Subscriptions -GroupName, -EnablePolling Resets an incremental group: re-registers its members with the Capture Agent. The group must not be busy.
Restore-GroupReplay -GroupName, -NewPosition, -IsTX Replays a group's changes from a position. Use it only with Stelo Support.
Restore-GroupMember -GroupName, -SourceName, -SubscriptionName, -NewPosition, -IsTX The same for one member.
Confirm-Target -GroupName, -SubscriptionName Starts a row-count check of a member's source and destination tables.
Show-TargetCheckResults -GroupName, -SubscriptionName Shows the results of the row-count check.

Statistics and status

Cmdlet Parameters What it does
Show-GroupStatistics -GroupName Lists a group's replication statistics.
Show-GroupMemberStatistics -GroupName, -SourceName, -SubscriptionName Lists a member's statistics.
Show-SubscriptionStatistics -SourceName, -SubscriptionName Lists a subscription's statistics.
Reset-GroupStatistics, Reset-SubscriptionStatistics -GroupName; -SourceName, -SubscriptionName Deletes the statistics of a group or subscription.
Show-ReplicationStatus -SourceName, -SubscriptionName Shows a subscription's replication status.
Show-Connection — Lists the service's open connections.
Remove-Connection -ConnectionID Closes a connection.
Show-RBACJournal [-Limit = 1000] Lists audit journal entries.
Remove-RBACJournal [-WhenRqsList], [-CutoffDate] Deletes audit journal entries: the listed ones, or those older than the date.

Service properties

See Service properties for the names and values.

Cmdlet Parameters What it does
Get-BooleanProperty, Get-Int32Property, Get-StringProperty -Name Returns a property's value. Passwords can't be read.
Set-BooleanProperty, Set-Int32Property, Set-StringProperty -Name, -Value Changes a property.
Export-Properties -JsonFileOut Writes all properties to a JSON file.
Import-Properties -JsonFile Changes the properties in a JSON file, for example {"addUnsupportedDrivers": true}. Only the properties in the file change.

Schedules and macros

Cmdlet Parameters What it does
Show-Scheduler [-Status], [-Enabled], [-Name] Lists the scheduled groups and subscriptions, as on the Scheduled Tasks tab of the Monitoring page.
Set-GroupSchedule -GroupName, -JsonSchedulesFile Sets a group's schedule.
Set-SubscriptionSchedule -SourceName, -SubscriptionName, -JsonSchedulesFile Sets a snapshot subscription's schedule.
Show-SqdrMacros [-DbmsType = -1 (all)], [-IncludeGlobal = $true] Lists SQDR macros.
Add-SqdrMacro -MacroSignature, -DbmsType, [-Comment], -MacroValue Creates a macro.
Set-SqdrMacro -Id, -MacroSignature, -DbmsType, [-Comment], -MacroValue Changes a macro.
Remove-SqdrMacro -MacroName, -DbmsType Deletes a macro.
Export-SqdrMacros, Import-SqdrMacros -JsonFileOut; -JsonFile Writes the macros to a JSON file, or creates them from one.

Browsing databases

Cmdlet Parameters What it does
Show-DataSources, Show-Drivers — Lists the ODBC data sources or drivers on the service's computer.
Show-DSN -DsnName, -UserID, -Password, [-ConnectionStringOverride], [-UseIntegratedSecurity = 0] Shows information about an ODBC data source.
Read-SQLQualifiers, Read-SQLSchemas, Read-SQLTables, Read-SQLColumns, Read-SQLPrimaryKeys -SrcDestType, -SrcDestName, then catalog, schema, table or column filters List a source's or destination's databases, schemas, tables, columns or primary keys.
Read-SQLGetTypeInfo -SrcDestType, -SrcDestName Lists the data types a source or destination reports. See Data type mapping.
Read-SqlServerDatabases -SrcDestType, -SrcDestName Lists the databases of a SQL Server source or destination.
Show-Members -SrcDestType, -SrcDestName, -LibraryName, -FileName Lists the members of a Db2 for i file.
Read-TableIndexes, Read-TableConstraints -SourceName, -SubscriptionName, table and incremental filters List a table's indexes or constraints.
Show-IRTableInfo, Show-IRIndex -SourceName, table filters Show a source table's incremental (Stelo Capture) information or index.

Other

Cmdlet Parameters What it does
Show-ServiceUserid — Shows the account the Replicator Service runs as.
Get-Licensed — Fails if the Replicator Service isn't licensed.
Test-Email -ToEmailAddress, -FromEmailAddress, -SmtpServer, -Port, -UserID, [-Password], [-MailEncryption = 0], [-Token] Sends a test email with the given settings.
Send-Logs -Option 1, [-FtpServer], [-UserID], [-Password] Uploads the service's logs to Stelo Support.
Invoke-Query -Script, [-Where], [-OrderBy] Runs one of the control database queries shipped with SQDR. Windows only, on the service's computer.
Invoke-AgentQuery -SourceName, -Script, [-Where], [-OrderBy], [-Page], [-PageSize = 200] Runs a query shipped with SQDR against a source's Capture Agent.
Test-ServiceDown -Wait Stops the Replicator Service. Despite its name, it isn't a test.

Get-Command also lists Enable-KeyLog and Show-KeyLogEnabled. The Replicator Service doesn't support them: they fail with "Not implemented". To record the changes applied to a group's tables, see Key log.

Sample scripts

These scripts are installed next to the module. Each takes an optional last parameter, host:port (default 127.0.0.1:7738, or user:password@host:port with Role Based Access Control), and finds the module itself.

Script Usage What it does
pause-grp.ps1, resume-grp.ps1 .\pause-grp.ps1 <IRGroupName> [host:port] Pauses or resumes an incremental group. % wildcards allowed.
run-grp.ps1 .\run-grp.ps1 <GroupName> [host:port] Runs a group.
run-sub.ps1 .\run-sub.ps1 <Source> <SubscriptionName> [host:port] Runs a subscription.
dlt-sub.ps1 .\dlt-sub.ps1 <Source> <SubscriptionName> [host:port] Deletes a subscription.
move-sub.ps1 .\move-sub.ps1 <Source> <SubscriptionName> <ToGroup> [host:port] Moves a subscription between two paused incremental groups.
chk-subs.ps1 .\chk-subs.ps1 <IRGroupName> <SubscriptionName> [host:port] Compares source and destination row counts, allowing for changes not yet applied. % wildcards allowed.
show-irgrp.ps1 .\show-irgrp.ps1 [host:port] Shows the incremental groups' properties.

TargetChecker and PauseResumeIRGroup

Two VBScript tools, kept for jobs written for SQDR 5, run the sample scripts above. They're in the same Tools folder (C:\Program Files\StarQuest\SQDR\Tools by default) and need Windows PowerShell 5.1 or later. VBScript is Windows only: on Docker, run the PowerShell scripts in pwsh instead.

Both tools call their script from the current folder and connect to the Replicator Service on the same computer (127.0.0.1:7738). So:

  • run them from the Tools folder, with cscript (they print their results to the console);
  • with Role Based Access Control on, run the PowerShell scripts directly with user:password@host:port instead.

TargetChecker: compare row counts

What it's for. TargetChecker checks whether an incremental group's destination tables hold the rows they should: it compares each member's source and destination row counts, allowing for the changes the Capture Agent has staged but the group hasn't applied yet. Use it when you suspect a member is out of step with its source, for example after row count errors, and before deciding to baseline it again.

How it works. For each member, the Replicator Service counts the rows of the source and destination tables, and asks the Capture Agent for the net effect of the staged changes (inserts minus deletes) (Confirm-Target). It saves the three numbers and the check time with the member, then lists them (Show-TargetCheckResults). Counting reads every row of both tables, so a check of large tables takes a while.

Run it

cd "C:\Program Files\StarQuest\SQDR\Tools"
cscript /nologo TargetChecker.vbs [group [subscription]]

Without arguments it checks every member of every incremental group. The names accept the SQL wildcard %, for example cscript /nologo TargetChecker.vbs SALES% %. It runs chk-subs.ps1 <group> <subscription>, which you can also run in PowerShell (.\chk-subs.ps1 SALES_GROUP % [host:port]).

Read the results. For each member checked:

Column Meaning
SourceCount Rows in the source table.
DeltaCount Net rows of the changes staged but not yet applied (inserts minus deletes).
DestCount Rows in the destination table.
CheckDiff SourceCount - (DeltaCount + DestCount). 0 means the destination matches the source.
DeltaState The state of the staged-change count reported by the Capture Agent; -1 means a count couldn't be obtained.
CheckTime When the check ran.

The same results, from the last check of each member, are on the Query tab of Service Settings: TargetChecker.sql lists only the members with a difference, a check older than the member's last baseline, or a baseline required (an empty result means no difference was found); TargetChecker_LastTime.sql shows the earliest and latest check times. See Query.

For differences that remain, see Row count errors after a baseline and Incorrect row count information (Oracle source).

PauseResumeIRGroup: pause or resume a group

What it's for. Pausing and resuming an incremental group from a scheduled job, for example around a backup or maintenance of the destination database.

cd "C:\Program Files\StarQuest\SQDR\Tools"
cscript /nologo PauseResumeIRGroup.vbs <IRGroupName> 0
cscript /nologo PauseResumeIRGroup.vbs <IRGroupName> 1

0 pauses the group (it runs pause-grp.ps1); 1 resumes it (resume-grp.ps1). To schedule it with Windows Task Scheduler, set the task's Start in folder to the Tools folder. Without VBScript, use .\pause-grp.ps1 <IRGroupName> or .\resume-grp.ps1 <IRGroupName>, or the cmdlet Enable-IncrementalPolling (see Pause and resume an incremental group).