Thor Logo dbatools

Enable-DbaReplPublishing

View Source
Jess Pomfret (@jpomfret), jesspomfret.com
Windows, Linux, macOS

Synopsis

Configures a SQL Server instance as a replication publisher on an existing distributor.

Description

Configures a SQL Server instance to publish data for replication by creating the necessary publisher configuration on an existing distributor. This is typically the second step in setting up SQL Server replication, after the distributor has been configured with Enable-DbaReplDistributor. The function sets up the snapshot working directory, configures publisher security authentication, and registers the instance as a publisher with the distribution database. The target instance must already be configured as a distributor before running this command.

Syntax

Enable-DbaReplPublishing
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [[-SnapshotShare] <String>]
    [[-PublisherSqlLogin] <PSCredential>]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Enable-DbaReplPublishing -SqlInstance SqlBox1\Instance2

Enables replication publishing for instance SqlBox1\Instance2 using Windows Auth and the default InstallDataDirectory\ReplData as the snapshot folder

Required Parameters

-SqlInstance

The target SQL Server instance or instances.

PropertyValue
Alias
RequiredTrue
Pipelinetrue (ByValue)
Default Value

Optional Parameters

-SqlCredential

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-SnapshotShare

Specifies the network share path where replication snapshot files will be stored and accessed by subscribers.
Use this when you need snapshot files in a specific location for network access or storage requirements.
Defaults to InstallDataDirectory\ReplData if not specified.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-PublisherSqlLogin

SQL Server login credentials to use for publisher security authentication instead of Windows Authentication.
Use this when the distributor and publisher are in different domains or when Windows Authentication is not available.
Windows Authentication is used by default and is the recommended method for security.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with “sea of red” exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this “nice by default” feature off and enables you to catch exceptions with your own try/catch.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default ValueFalse
-WhatIf

If this switch is enabled, no actions are performed but informational messages will be displayed that explain what would happen if the command were to run.

PropertyValue
Aliaswi
RequiredFalse
Pipelinefalse
Default Value
-Confirm

If this switch is enabled, you will be prompted for confirmation before executing any operations that change state.

PropertyValue
Aliascf
RequiredFalse
Pipelinefalse
Default Value

Outputs

Microsoft.SqlServer.Replication.ReplicationServer

Returns one ReplicationServer object per instance specified, representing the publisher configuration. The object is refreshed after the publishing configuration is created, reflecting the updated replication state.

Default display properties (via Select-DefaultView):

  • ComputerName: The name of the computer hosting the SQL Server instance
  • InstanceName: The SQL Server instance name
  • SqlInstance: The full SQL Server instance name (computer\instance)
  • IsDistributor: Boolean indicating whether this instance is configured as a distributor
  • IsPublisher: Boolean indicating whether this instance is configured as a publisher (should be True after this command completes)
  • DistributionServer: The name of the server configured as the distributor
  • DistributionDatabase: The name of the distribution database

Additional properties available (from SMO ReplicationServer object):

  • DistributionDatabases: Collection of distribution databases configured on the instance
  • PublisherConnections: Collection of publishers configured on the distributor
  • Distributors: Collection of distributors configured on this instance
  • RegisteredSubscribers: Collection of registered subscribers
  • Publishers: Collection of publishers configured on the distributor All properties from the base SMO ReplicationServer object are accessible through Select-Object *.