Skip to content

Instantly share code, notes, and snippets.

@shadyrudy
Created February 22, 2023 05:07
Show Gist options
  • Save shadyrudy/d4a3e44324efed436509bee48be4ce37 to your computer and use it in GitHub Desktop.
Save shadyrudy/d4a3e44324efed436509bee48be4ce37 to your computer and use it in GitHub Desktop.
Get replication articles from the distribution database.
function Get-DbaReplicationArticle {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string]$SqlInstance,
[Parameter(Mandatory=$true)]
[string]$Database
)
Import-Module SqlServer
$query = @"
SELECT
publisher_db AS DatabaseName,
publication AS PublicationName,
article AS ArticleName,
source_owner AS SchemaName,
source_object AS ObjectName
FROM
msarticles
WHERE
publisher_db = '$Database'
"@
$results = Invoke-DbaQuery -SqlInstance $SqlInstance -Database 'distribution' -Query $query
if ($results.Count -eq 0) {
return @()
}
$articles = foreach ($result in $results) {
[PSCustomObject]@{
DatabaseName = $result.DatabaseName
PublicationName = $result.PublicationName
ArticleName = $result.ArticleName
SchemaName = $result.SchemaName
ObjectName = $result.ObjectName
}
}
return $articles
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment