Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

create new login with powershell Expand / Collapse
Author
Message
Posted Friday, September 20, 2013 5:43 AM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, November 18, 2013 11:46 PM
Points: 72, Visits: 316
I need to create create new login ( domain user ) with powershell?

I used this script:

[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO')|Out-Null
$Instance="*****machine name******"
$LoginName="***Domain User********"
$Password="*****password*****"
$DBName="master"

$Server=New-Object ("Microsoft.SqlServer.Management.SMO.Server") $instance
$Login=$Server.Logins.Item($LoginName)
$Login=New-Object ("Microsoft.SqlServer.Management.SMO.Login") ($Server, $LoginName)
$Login.LoginType=[Microsoft.SqlServer.Management.Smo.LoginType]::SqlLogin
$Login.DefaultDatabase=$DBName
$Login.Create($Password)



but script failed


ERROR:

New-Object : Exception calling ".ctor" with "2" argument(s): "SetParent failed for Login 'user name'. "
At line:1 char:18
+ $Login=New-Object <<<< ("Microsoft.SqlServer.Management.SMO.Login") ($Server, $LoginName)
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand




Post #1496821
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse