Advertisement
Guest User

Untitled

a guest
Aug 29th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. function ReadData {
  2. Param (
  3. [string]$username
  4. )
  5. $DBServer = "WUSAZEATEQADB01"
  6. $DBName = "Helpdesk_UserTool"
  7. $sqlConnection = New-Object System.Data.SqlClient.SqlConnection
  8. $sqlConnection.ConnectionString = "Server=$DBServer;Database=$DBName;Integrated Security=False;User Id = HelpDesk_User;password = ZECqBDz1"
  9.  
  10. $query = "SELECT EmpId FROM Employee WHERE UserName = @un;"
  11.  
  12. $sqlCommand = New-Object System.Data.SqlClient.SqlCommand
  13. $sqlCommand.Connection = $sqlConnection
  14. $sqlCommand.CommandText = $query
  15.  
  16. $sqlCommand.Parameters.Add("@un", $username)
  17.  
  18. $sqlConnection.Open()
  19. $result = $sqlCommand.ExecuteReader()
  20. $sqlConnection.Close()
  21.  
  22. Write-Host $result
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement