Hi,I have a script I am writing to make life easier for myself around requests for new Database environments by our developers. (Dev/Test/Live).All was going well until I stumbled on a little "issue-et". I can create my db and users on one SQL instance Fine. When I created a loop to do this for each instance the second time around the loop I get the following error. from this line *** $SQLuser.Create("123456789Ac") ** [code="other"]Exception calling "Create" with "1" argument(s): "Create failed for Login 'XXzzx2314gsrdf_user'. "At S:\Al\Scripts\PS script\New Database\CreateNewDatabase.ps1:108 char:16+ $SQLuser.Create <<<< ("123456789Ac") + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException[/code]An extract of my code below$DevServer = "MSSQL\DEV"$TestServer = "MSSQL\TEST"$LiveServer = "MSSQL\LIVE"$AllServers = $DevServer,$TestServer,$LiveServer .....get db name and user details here....[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | Out-Nullforeach ($server in $AllServers){$sqlSrv = New-Object Microsoft.SqlServer.Management.Smo.Server ($server)$SQLLoginname = $DatabaseName + "_user"$SQLuser = new-object Microsoft.SqlServer.Management.Smo.Login -ArgumentList ($sqlSrv,$SQLLoginname)$SQLuser.Name = $SQLLoginname$SQLuser.LoginType = "SQLLogin"$SQLuser.PasswordExpirationEnabled = $false$SQLuser.DefaultDatabase = $DatabaseName$SQLuser.PasswordPolicyEnforced = $false$SQLuser.Create("123456789Ac")# Windows Group$SQLLoginname = "MyDomain\$ADSQLGroup"$WGuser = new-object Microsoft.SqlServer.Management.Smo.Login -ArgumentList ($sqlSrv,$SQLLoginname)$WGuser.Name = $SQLLoginname$WGuser.LoginType = "WindowsGroup"$WGuser.DefaultDatabase = $DatabaseName$WGuser.Create()Remove-Variable -name sqlSrvRemove-Variable -name SQLuserRemove-Variable -name WGuser }Any help I can get on why I get the error would be great. (No alternative suggestions please) :-D
↧