April 24, 2015 at 11:34 am
I had a need to test something recently and wanted to create multiple logins. Other than using a batch like this:
CREATE LOGIN TestUser1 WITH PASSWORD = 'UserT3stUn0';
CREATE LOGIN TestUser2 WITH PASSWORD = 'UserT3stD0s';
CREATE LOGIN TestUser3 WITH PASSWORD = 'UserT3stTr#s';
CREATE LOGIN TestUser4 WITH PASSWORD = 'UserT3stQuatr0';
CREATE LOGIN TestUser5 WITH PASSWORD = 'UserT3stCinc0';
Are there any suggestions for how to do this? Since it's security, I'm guessing any need for this would be using an Excel sheet or flat file with names/pwds and driving a CREATE LOGIN batch or PoSh from that.
April 24, 2015 at 2:40 pm
Yeahhhh.... PoSH... NOT! 😉
If they're just test users that will go away right after you're done testing, then something like the following might do.
DECLARE @SQL VARCHAR(MAX)
,@Logins SMALLINT = 1435
;
SELECT TOP (@Logins)
@SQL = ISNULL(@SQL,'')
+ REPLACE(REPLACE('
CREATE LOGIN TestUser<<Suffix>> WITH PASSWORD = "UserT3$t<<Suffix>>";'
,'"','')
,'<<Suffix>>',RIGHT(ROW_NUMBER() OVER (ORDER BY (SELECT NULL))+10000,4))
FROM sys.all_columns
;
PRINT @SQL
;
--EXEC (SQL)
;
If it needs something more sophisticated, post back with some details.
--Jeff Moden
Change is inevitable... Change for the better is not.
April 24, 2015 at 3:20 pm
Yeah, that's probably the best type of solution, Jeff. Didn't think about tally tabling that, but it's a good use with dynamic SQL for a limited number of items, along with adding users.
Thanks
April 26, 2015 at 11:45 am
Thanks for the feedback, Steve.
As for the "user" part of this, we also used similar code to create the code at the DOS level to create the AD users and add them to a group for the "load testing" that we do once a quarter. We also generated similar code to undo all of it.
And, of course (you know me), we executed all of it through calls to xp_CmdShell.
--Jeff Moden
Change is inevitable... Change for the better is not.
April 26, 2015 at 1:55 pm
April 26, 2015 at 2:09 pm
Eirikur Eiriksson (4/26/2015)
Jeff Moden (4/24/2015)
Yeahhhh.... PoSH... NOT! 😉Surely you meant "Not posh enough":-D
😎
Don't call me "Shirley". 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
April 26, 2015 at 2:20 pm
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply