달력

8

« 2015/8 »

  • 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

'2015/08/12'에 해당되는 글 1

  1. 2015.08.12 PowerShell로 SQL 쿼리
2015. 8. 12. 09:20

PowerShell로 SQL 쿼리 Etc.2015. 8. 12. 09:20

Param(

  [Parameter(Mandatory=$True)]

  [string]$SQLServer,

  [Parameter(Mandatory=$True)]

  [string]$SQLDBName,

  [Parameter(Mandatory=$True)]

  [string]$UserID,

  [Parameter(Mandatory=$True)]

  [string]$UserPW

)


$SqlQuery = "SELECT * FROM TABLE_VIEW"


$SqlConnection = New-Object System.Data.SqlClient.SqlConnection

# $SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; Integrated Security = True"

$SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; uid="+$UserID+"; pwd="+$UserPW


$SqlCmd = New-Object System.Data.SqlClient.SqlCommand

$SqlCmd.CommandText = $SqlQuery

$SqlCmd.Connection = $SqlConnection

$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter

$SqlAdapter.SelectCommand = $SqlCmd

$DataSet = New-Object System.Data.DataSet

$SqlAdapter.Fill($DataSet) | Out-Null

$SqlConnection.Close()


foreach ($row in $DataSet.Tables[0].Rows) {

  $Row1 = $row[0].ToString().Trim()

  $Row2 = $row[1].ToString().Trim()

  $Row3 = $row[2].ToString().Trim()

  Write-Host $Row1, $Row2, $Row3

}




:
Posted by 커널64