1
- # Created by EGGSTOASTBACON :: https://github.com/eggstoastbacon
2
-
3
1
# SQL MANAGEMENT STUDIO SHOULD BE INSTALLED FROM WHERE YOU RUN THIS
4
2
# The server this is run from should have SQL Port and WMI access to the servers you intend to connect to.
5
3
# You will require file sqlserver.psd1, change the path to it below.
@@ -47,8 +45,9 @@ foreach ($IP in $IPs) {
47
45
$sysinfo = Get-WmiObject - computer $IP - credential $wmiCredentials - Class Win32_ComputerSystem - ErrorAction SilentlyContinue
48
46
$server = $sysinfo.Name
49
47
48
+
50
49
$portCheck = Test-NetConnection - computername $IP - port $SQLPort
51
- if ($portCheck.tcpTestSucceeded -like " True" ) { $portPassed = " True" }else { write-host " Unable to Connect to $IP on $SQLPort " }
50
+ if ($portCheck.tcpTestSucceeded -like " True" ) { $portPassed = " True" }else { write-host " Unable to Connect to $IP on $SQLPort " }
52
51
53
52
if ($portPassed -like " True" ) {
54
53
@@ -116,10 +115,12 @@ foreach ($IP in $IPs) {
116
115
$userrole = $userrole + " public"
117
116
$userrole
118
117
118
+
119
119
if ($login.name -notlike " *dbo*" -and $login.name -notlike " sys" `
120
120
-and $login.name -notlike " guest" -and $login.name -notlike " *##*" `
121
121
-and $login.name -notlike " *MS_*" -and $login.name -notlike " *_SCHEMA*" ) {
122
122
123
+
123
124
# Create an object and write properties about the account
124
125
$row = New-Object PSObject
125
126
$row | Add-Member - MemberType NoteProperty - Name " Database" - Value " Server Login"
@@ -143,7 +144,7 @@ foreach ($IP in $IPs) {
143
144
if ($srv.DatabaseEngineEdition -like " *Enterprise*" ) { } else { $AGNAME = " No SQL Connection" }
144
145
145
146
# Write SQL Login Information to a SQL Row
146
- $query = "
147
+ $query = "
147
148
INSERT into $storeTABLE (IP,CNAME,DB,DOMAIN,LOGIN,CREATED,MODIFIED,LOGINTYPE,SERVICEACCOUNT,ROLES,DISABLED,DATE,MONTH,DAY,YEAR,AGNAME,LISNAME,CLUNAME) VALUES ('$IP ','$Server ','$Databasename ','$DOMAIN ','$LoginName ','$LoginCreateDate ','$LoginDateLastModified ','$LoginLoginType ','$ServiceAccount ','$userrole ','$loginisdisabled ','$date ','$Month ','$Day ','$Year ','$agname ','$listenername ','$clustername ')
148
149
"
149
150
Invoke-Sqlcmd - ServerInstance $storeSQLServer - Database $storeSQLdatabase - Query $query - MaxCharLength 3000 - Verbose
@@ -199,7 +200,7 @@ INSERT into $storeTABLE (IP,CNAME,DB,DOMAIN,LOGIN,CREATED,MODIFIED,LOGINTYPE,SER
199
200
200
201
if ($srv.DatabaseEngineEdition -like " *$SQLEdition *" ) { } else { $AGNAME = " No SQL Connection" }
201
202
202
- $query = "
203
+ $query = "
203
204
INSERT into $storeTable (IP,CNAME,DB,DOMAIN,LOGIN,CREATED,MODIFIED,LOGINTYPE,SERVICEACCOUNT,ROLES,DISABLED,DATE,MONTH,DAY,YEAR,AGNAME,LISNAME,CLUNAME) VALUES ('$IP ','$Server ','$Databasename ','$DOMAIN ','$UserName ','$UserCreateDate ','$UserDateLastModified ','$UserLoginType ','$ServiceAccount ','$userrole ','$userisdisabled ','$date ','$Month ','$Day ','$Year ','$agname ','$listenername ','$clustername ')
204
205
"
205
206
Invoke-Sqlcmd - ServerInstance $storeSQLServer - Database $storeSQLdatabase - Query $query - MaxCharLength 3000 - Verbose
@@ -212,4 +213,4 @@ INSERT into $storeTable (IP,CNAME,DB,DOMAIN,LOGIN,CREATED,MODIFIED,LOGINTYPE,SER
212
213
213
214
}
214
215
}
215
-
216
+
0 commit comments