EDIT 1 : I am able to create replication objects successfully via Windows PowerShell ISE but NOT PowerGUI. The script used to run successfully on my 32 bit machine and now errors on my 64. Issue looks to be an environmental issue.
I'm attempting to connect to my distribution SQL Server instance using SQL Authentication from powershell and create a replication object. I am unable test connecting using Windows Authentication.
The following code which originates from http://sqlpsx.codeplex.com/ and the loaded module Repl (Repl.psm1).
$sqlServer = "SQL Server"
$Username = "UserName"
$Password = "Password"
[Microsoft.SqlServer.Management.Common.ServerConnection]$con = Get-SqlConnection $sqlServer $username $password
Write-host "Get-ReplServer $($con.ServerInstance)"
$repl = new-object ("Microsoft.SqlServer.Replication.ReplicationServer") $con
or more specifically
new-object ("Microsoft.SqlServer.Replication.ReplicationServer") $con
generates the following error
New-Object : Cannot find an overload for "ReplicationServer" and the argument count: "1".
At line:25 char:19
+ $repl = new-object <<<< ("Microsoft.SqlServer.Replication.ReplicationServer") $con
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
The server connection code
[Microsoft.SqlServer.Management.Common.ServerConnection]$con = Get-SqlConnection $sqlServer $username $password
completes successfully and returns correct server information
The SQL server version is
Microsoft SQL Server 2008 R2 (SP2) - 10.50.4000.0 (X64)
Jun 28 2012 08:36:30
Copyright (c) Microsoft Corporation
Developer Edition (64-bit) on Windows NT 6.1 <X64> (Build 7600: ) (Hypervisor)
and PowerShell version
Major Minor Build Revision
----- ----- ----- --------
2 0 -1 -1
My issues appears to be the same as Issue with connecting to ReplicationServer with sql authentication. However the solution from Chad Miller does not resolve my issue i.e.
$con.Connect()
$repl = new-object ("Microsoft.SqlServer.Replication.ReplicationServer") $con
Any ideals would be much appreciated.