-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathSQL_Query.ps1
More file actions
31 lines (25 loc) · 951 Bytes
/
SQL_Query.ps1
File metadata and controls
31 lines (25 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
$Global:SCCMSQLSERVER = "DB-SRV\SQL"
$Global:DBNAME = "DATABASE"
$Global:uid = "sa"
$Global:pwd = "D4passwd"
Try{
$SQLConnection = New-Object System.Data.SQLClient.SQLConnection
$SQLConnection.ConnectionString ="server=$SCCMSQLSERVER;database=$DBNAME;Integrated Security=False; uid=$uid; pwd=$pwd"
$SQLConnection.Open()
}
catch{
[System.Windows.Forms.MessageBox]::Show("Failed to connect SQL Server:")
}
$SQLCommand = New-Object System.Data.SqlClient.SqlCommand
$SQLCommand.CommandText = "SELECT is_srvrolemember('sysadmin','user-to-check')" #"SELECT @@version" #
$SQLCommand.Connection = $SQLConnection
$SQLAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SQLCommand
$SQLDataset = New-Object System.Data.DataSet
$SqlAdapter.fill($SQLDataset) | out-null
$tablevalue = @()
foreach ($data in $SQLDataset.tables[0]){
$tablevalue = $data[0]
$tablevalue
}
$SQLConnection.close()