SetParent failed for Login

I’m back for another boring Powershell blog post, that might help some people

I was getting this strange error:

New-Object : Exception calling “.ctor” with “2” argument(s): “SetParent failed for Login ‘GFreeSQL’. ”
At line:1 char:22
+ $WindowsGroupLogin = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Log …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

It turns out that I needed to specify the domain in the server name, because I was running it from a different domain.
So it should look like this:

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SqlServer.Smo”) | Out-Null;
$servername = “sqlserver12345.gfree.lan
$ServerObject = new-Object Microsoft.SqlServer.Management.Smo.Server($servername )
$LoginName = “GFreeSQL”;
Microsoft.SqlServer.Management.Smo.Login -ArgumentList $ServerObject,$LoginName

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s