Skip to content

Commit 5834bf4

Browse files
Remove-DbaReplArticle - Add replication library loading to fix Article type error (#9892)
2 parents 8ef372e + 1abe7ec commit 5834bf4

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

dbatools.psm1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,16 @@ if (-not (Test-Path -Path "$script:PSModuleRoot\dbatools.dat") -or $script:seria
184184

185185
Write-ImportTime -Text "Loading internal commands via dotsource"
186186

187+
# Load replication libraries before dot-sourcing functions with replication type constraints
188+
# This is required for Remove-DbaReplArticle and Remove-DbaReplPublication which have
189+
# [Microsoft.SqlServer.Replication.*] type constraints in their parameters
190+
try {
191+
Add-ReplicationLibrary -ErrorAction SilentlyContinue
192+
} catch {
193+
# Silently ignore if replication libraries can't be loaded
194+
# The individual commands will handle this when they're executed
195+
}
196+
187197
# All exported functions
188198
foreach ($file in (Get-ChildItem -Path "$script:PSModuleRoot/public/" -Recurse -Filter *.ps1)) {
189199
. $file.FullName

public/Remove-DbaReplArticle.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,12 @@ function Remove-DbaReplArticle {
8888
[String]$Name,
8989
#[Switch]$DropObjectOnSubscriber,
9090
[Parameter(ValueFromPipeline)]
91-
[Microsoft.SqlServer.Replication.Article[]]$InputObject,
91+
[psobject[]]$InputObject,
9292
[Switch]$EnableException
9393
)
9494

9595
begin {
96+
Add-ReplicationLibrary
9697
$articles = @( )
9798
}
9899

public/Remove-DbaReplPublication.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ function Remove-DbaReplPublication {
6565
[String]$Database,
6666
[String]$Name,
6767
[parameter(ValueFromPipeline)]
68-
[Microsoft.SqlServer.Replication.Publication[]]$InputObject,
68+
[psobject[]]$InputObject,
6969
[Switch]$EnableException
7070
)
7171
begin {
72+
Add-ReplicationLibrary
7273
$publications = @( )
7374
}
7475
process {

0 commit comments

Comments
 (0)