Step 1 :
Open SSMS
Step 2 :
Right Click on your Database and start PowerShell.
Paste the below snippet.
Open SSMS
Step 2 :
Right Click on your Database and start PowerShell.
Paste the below snippet.
Function SQL_CONN1 ($Query) {$SqlConnection = New-Object System.Data.SqlClient.SqlConnection$SqlConnection.ConnectionString = "Server=Your_Server;Database=Your_DB;Integrated Security=True"$SqlCmd = New-Object System.Data.SqlClient.SqlCommand$SqlCmd.Connection = $SqlConnection$SqlCmd.CommandText = $Query$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter$SqlAdapter.SelectCommand = $SqlCmd$DataSet = New-Object System.Data.DataSet$a=$SqlAdapter.Fill($DataSet)$SqlConnection.Close()$DataSet.Tables[0] }SQL_CONN1 “select * from PowerShell_Test”
No comments:
Post a Comment