September 20, 2013 at 5:43 am
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
Viewing 0 posts
You must be logged in to reply to this topic. Login to reply