The issue you're experiencing is likely due to the SQL Server upgrade from 2019 to 2022, which changed the version of the Microsoft.SqlServer.ConnectionInfo
assembly.
To resolve this:
Option 1: Install SQL Server 2022 Management Studio
Installing SQL Server 2022 Management Studio will update the assemblies to the latest version.
Option 2: Update SQL Server PowerShell Module
Update the SQL Server PowerShell module to the latest version using:
Install-Module -Name SqlServer -Force
Option 3: Assembly Redirect
Create a configuration file (ReplicationServer.exe.config
) in the same directory as your script with the following content:
<?xml version="1.0"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.SqlServer.ConnectionInfo" publicKeyToken="89845dcd8080cc91" culture="neutral"/>
<bindingRedirect oldVersion="17.100.0.0" newVersion="18.100.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Option 4: Use SQL Server 2022-specific assemblies
Download and install the Microsoft.SqlServer.Replication.dll and Microsoft.SqlServer.ConnectionInfo.dll assemblies for SQL Server 2022.
Verify the assembly versions:
[System.Reflection.Assembly]::LoadFrom("C:\Path\To\Microsoft.SqlServer.ConnectionInfo.dll").GetName().Version
Adjust your script to use the updated assemblies:
Add-Type -Path "C:\Path\To\Microsoft.SqlServer.Replication.dll"
Add-Type -Path "C:\Path\To\Microsoft.SqlServer.ConnectionInfo.dll"
New-Object "Microsoft.SqlServer.Replication.ReplicationServer" $sqlserver
If none of these options work, provide more details about your environment and script for further assistance.