I'm playing around with a little script to add new users. It's just for my own practice/learning fun time.
So far it looks like this:
declare @user varchar (100),
set @user = 'somedude'
if exists ( select * from syslogins where name like '%' + @User + '%')
set @LiveUser = 1
set @LiveUser = 0
if @LiveUser = 0
set @sqls = 'CREATE LOGIN [domain\' + @user + '] FROM WINDOWS WITH DEFAULT_DATABASE=[somedb]'
print 'User is now in the system'
print 'User already in the system'
The one problem I am getting is if 'somedude' isn't in AD. Is there anyway using t-sql to check this?
I know you can check the opposite way with sp_validatelogins but wasn't sure if you could check if a potential new user was in AD or not.
I'd like to have a pretty message instead of
Windows NT user or group 'domain\somedude' not found. Check the name again.