Created
February 22, 2023 05:07
-
-
Save shadyrudy/d4a3e44324efed436509bee48be4ce37 to your computer and use it in GitHub Desktop.
Get replication articles from the distribution database.
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 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