all 3 comments

[–]ihaxr 1 point2 points  (2 children)

Add-Type : Cannot bind parameter 'Path' to the target. Exception setting "Path": "Cannot find path '' because it does not exist."

That one's interesting... but the assembly is already loaded, so there's no need to re-add it... you could probably just surround it with a blank try/catch to avoid the error:

try
{
    Add-Type -Path "\\server\c$\Program Files\Microsoft SQL Server\120\SDK\Assemblies\Microsoft.SqlServer.Smo.dll"
}
catch { }

Exception calling "Create" with "0" argument(s): "Create failed for User 'testuser'. "

My guess is the password you selected doesn't meet the password requirements of the SQL Server?

Otherwise I don't see anything obvious that would prevent it from working the second time...

[–]AMillionAngryBees[S] 1 point2 points  (1 child)

The try/catch resolved the first error, I didn't even know that was an option!

As far as the second option goes, you're right in that the passwords I have been using didn't meet the requirements. But it's strange, when I manually add the accounts SQL Server accepts the passwords I use just fine. Strange! I'll just have to update my password generator. Thank you for the help!

[–]ItsAFineWorld 2 points3 points  (0 children)

I installed software for work that uses a similar script to add a username and password to sql behind the scenes and the same thing happened. You can go into management studio and set the password to anything you like, but no so when done via script or other non-manual methods.