Sign in
|
Join PowerShell.com!
|
Help
Home
PowerTips
Ask the Experts
Forums
Webcasts
Blogs
eBookV2
Script Library
Twitter Grid
Modules
QuickClick
Scripts
Snippets
Videos
Library
»
Script Library
»
SQL Server
»
Slideshow
SQL Server Slideshow
Share
|
Browse Library
Module Library
QuickClick Library
Script Library
Active Directory
BizTalk
Citrix
Clustering
Desktop
Exchange Server 2003
Exchange Server 2007
File System
Group Policy
Internet Information Server (IIS)
Local Accounts
Logs
Microsoft Office
Microsoft Team Foundation Server
MySQL
Networking
Registry
Remote Desktop Services
Remoting
Security
SharePoint
SQL Server
System Center Virtual Machine Manager
System Center Configuration Manager
System Center Operations Manager
Tutorial
Terminal Server
Using .Net
Virtual Server
VMware
Windows 7
Windows HPC
Windows Server 2000
Windows Server 2003
Windows Server 2008
Windows XP
WMI
Misc
Snippet Library
Video Library
Members Only
Tags
Access
AD
ADO
Analysis Server
Attributes
Backup
CheckDB
Connect
Connection String
Create database
Create table
CSV
Database
Port
PowerShell
Properties
Service
SMO
SQL
SQL Authentication
SQL Server
stop jobs
test-connection
Windows Authentication
WMI
View more
Sql Server Security Audit
cls
$server
=
'ENTER SERVER NAME HERE'
[
System.Reflection.Assembly
]::
LoadWithPartialName
(
"Microsoft.SqlServer.SMO"
) |
Out-Null
#this only looks at the default instance
$cn
=
new-object
system.data.SqlClient.SqlConnection
(
"Data Source=MSSQLSERVER;Integrated Security=SSPI;Initial Catalog=master"
);
$s
=
new-object
(
'Microsoft.SqlServer.Management.Smo.Server'
)
$server
#$val =$s.Logins | select Name, DefaultDatabase
function
getRoles(
$roles
){
if
(
$roles
.
EnumRoles
().
Count
-eq
0){
'<h4><b>NO ROLES<b/></h4>'
}
foreach
(
$role
in
$roles
.
EnumRoles
()){
$role
+
'<br/>'
}
}
function
buildADRow(
$rp
){
$mep
=
$r
| select
Login
$inGroup
=
(
Get-QADGroupMember
$mep
.
Login
-Enabled
-Indirect
-SizeLimit
18000 )
foreach
(
$account
in
$inGroup
){
'<tr>'
'<td></td>'
'<td>'
+
$account
.
NTAccountName
+
'</td>'
'<td>'
+
(getRoles(
$rp
))
+
'</td>'
'</tr>'
}
}
function
buildRow(
$rp
){
$t
=
$rp
| select
Name, Login
'<tr>'
'<td
colspan=2>'
if
(
$t
.
Login
-eq
''
){
$t
.
Name
+
'</td>'
}
else
{
$t
.
Login
+
'</td>'
}
'<td>'
+
(getRoles(
$rp
))
+
'</td>'
'</tr>'
}
$dbs
=
$s
.
Databases
'<html><style type="text/css">h4 {color:red;}</style><body>'
foreach
(
$db
in
$dbs
) {
'<br/><br/><br/>'
$dbname
=
$db
.
Name
$users
=
$db
.
Users
'<table border=1 width=100%>'
'<tr>
<td colspan=3 bgcolor=#C0C0C0><b>'
+
$dbname
+
'</b></td>
</tr>'
'<tr>
<td width=25%><b>SQL Account</b></td>
<td width=25%><b>Group Member</b></td>
<td width=25%><b>Rights</b></td>
</tr>'
if
(
$users
.
get_Count
()
-cge
1){
foreach
(
$r
in
$users
){
if
(
$r
.
get_HasDBAccess
()
-eq
'True'
){
if
(
$r
.
LoginType
-contains
'WindowsGroup'
){
buildRow(
$r
)
buildADRow(
$r
)
}
else
{
buildRow(
$r
)
}
}
}
}
'</table>'
}
'</body></html>'
Loading...
Sql Server...
Find All Domain...
Export Filestream...
Send SQL to...
Create Database...
Stop-Jobs
Set-SQL.ps1
Get-SQL.ps1
Get Database...
Execute MSSQL...
View all files
Copyright 2011 PowerShell.com. All rights reserved.