未加星标

Script : Disable all non sysadmin logins

字体大小 | |
[系统(windows) 所属分类 系统(windows) | 发布者 店小二03 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏

Hello Reader,

I am sharing a quick script to disable all non sysadmin logins for SQL Server. You can not disable windows groups so I tweaked this script to add Deny Connect for Windows Groups.

This script is handy if you are also seeing the error below :

Msg 15151, Level 16, State 1, Line 2
Cannot alter the login 'XXX\XXXXXX-XXX', because it does not exist or you do not have permission. USE master
GO
SELECT
case p.type_desc
when 'WINDOWS_GROUP'
then 'DENY CONNECT SQL TO [' + p.name + '] CASCADE;'
else
'ALTER LOGIN [' + p.name + '] DISABLE;'
end
, p.name AS [loginname] ,
p.type ,
p.type_desc ,
p.is_disabled,
CONVERT(VARCHAR(10),p.create_date ,101) AS [created],
CONVERT(VARCHAR(10),p.modify_date , 101) AS [update],
s.sysadmin, s.setupadmin, s.bulkadmin,s.dbcreator,s.dbcreator,s.diskadmin,
s.processadmin,s.setupadmin,s.serveradmin
FROM sys.server_principals p
JOIN sys.syslogins s ON p.sid = s.sid
WHERE p.type_desc IN ('SQL_LOGIN', 'WINDOWS_LOGIN', 'WINDOWS_GROUP')
and p.name NOT LIKE '##%'
AND (s.sysadmin <> 1
AND s.setupadmin <> 1
AND s.bulkadmin<> 1
AND s.dbcreator<> 1
AND s.diskadmin<> 1
AND s.processadmin<> 1
AND s.securityadmin<> 1
AND s.setupadmin<>1
AND s.serveradmin<> 1 )
GO

Sachin Diwakar

I am believer of ‘sharing knowledge’, after conducting many free trainings, now I am stuck with blogging. I am really enjoying blogging.. are you enjoying reading?


Script : Disable all non sysadmin logins
Script : Disable all non sysadmin logins
Script : Disable all non sysadmin logins

本文系统(windows)相关术语:三级网络技术 计算机三级网络技术 网络技术基础 计算机网络技术

主题: SQLWindowsSQL Server
分页:12
转载请注明
本文标题:Script : Disable all non sysadmin logins
本站链接:http://www.codesec.net/view/533394.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(windows) | 评论(0) | 阅读(42)