Closed mattcargile closed 6 days ago
Hi Matt,
here is (most likely) the bug that was introduced in #9078:
#This block is required so that correct error message can be returned to the user when incorrect database name is given or the database doesn't exists in the server.
if (-not $Database) {
$Database = $databases.Name
}
This only works in the first run, where $Database is not set and thus all the databases on that instance are used. On the second run, $Database is set (by the first run) and thus only the databases on the first instance are used.
To get this to work, $Database must remain unchanged, So for the loop, we need another variable which holds that databases that should be processed for this instance.
Maybe @sqlarticles can provide a fix for that. Or I can have a look in the next week or two.
Thanks @andreasjordan for looking into this.
I will try and reproduce the error and release a fix.
The test in that PR isn't actually validating the expected result. It only looks at the login name existing, it should also include validating it exist in all the databases too.
I had a look at the code and some other changes to the command in the last months. I don't know how to say that in a polite way so please excuse me, but this command is all messed up. There are a lot of bugs and the code in general is not very nice.
I will try refactor it again to clean things a little bit.
Verified issue does not already exist?
I have searched and found no existing issue
What error did you receive?
No error message. Login/User isn't added on all non-system databases.
Steps to Reproduce
Please confirm that you are running the most recent version of dbatools
Pulled from recent
development
.Other details or mentions
Some how
$getdbparam
retains multiple databases in theDatabase
key after the first full iteration of the$instance
loop. I'm not entirely sure how this happens. Maybe something with the handling of the cloning.I was playing with the below breakpoint.
What PowerShell host was used when producing this error
PowerShell Core (pwsh.exe)
PowerShell Host Version
SQL Server Edition and Build number
.NET Framework Version