Created
February 22, 2023 04:55
-
-
Save shadyrudy/e12c0111a940f116d4ebc8a76db072b9 to your computer and use it in GitHub Desktop.
Exports SQL Server replication articles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Export-SqlReplicationArticles { | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory=$true)] | |
[string]$ServerInstance, | |
[Parameter(Mandatory=$true)] | |
[string]$DatabaseName, | |
[Parameter(Mandatory=$true)] | |
[string]$OutputPath | |
) | |
Import-Module SqlServer | |
# Check if server instance exists | |
$serverExists = Test-Connection -ComputerName $ServerInstance -Count 1 -Quiet | |
if (-not $serverExists) { | |
Write-Error "Server instance '$ServerInstance' not found." | |
return | |
} | |
# Check if database exists | |
$databaseExists = Get-DbaDatabase -SqlInstance $ServerInstance -Database $DatabaseName -ErrorAction SilentlyContinue | |
if (-not $databaseExists) { | |
Write-Error "Database '$DatabaseName' not found on server instance '$ServerInstance'." | |
return | |
} | |
$articles = Get-DbaReplicationArticle -SqlInstance $ServerInstance -Database $DatabaseName | |
if ($articles.Count -eq 0) { | |
Write-Warning "No replication articles found in database '$DatabaseName' on server instance '$ServerInstance'." | |
return | |
} | |
$articles | Export-Csv -Path $OutputPath -NoTypeInformation | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment