Profile

Click to view full profile
Hi, I'm Veerapat Sriarunrungrueang, an expert in technology field, especially full stack web development and performance testing.This is my coding diary. I usually develop and keep code snippets or some tricks, and update to this diary when I have time. Nowadays, I've been giving counsel to many well-known firms in Thailand.
view more...

Thursday, February 18, 2016

How to add parameters into a WebRequest?

Conditional Logic in PowerShell


Operator
Description
-eq
Equal to
-lt
Less than
-gt
Greater than
-ge
Greater than or Eqaul to
-le
Less than or equal to
-ne
Not equal to


perator
Description
-not
Not
!
Not
-and
And
-or
Or

Query SQL in Powershell

The following snippet will query data from SQL into DataSet format:

$ServerName = "_ServerName_"
$DatabaseName =
"_DatabaseName_"
$Query =
"SELECT * FROM Table WHERE Column = 'XXX'"
#Timeout parameters
$QueryTimeout =
120
$ConnectionTimeout =
30
#Action of connecting to the Database and executing the query and returning results if there were any.
$conn=
New-Object System.Data.SqlClient.SQLConnection
$ConnectionString =
"Server={0};Database={1};Integrated Security=True;Connect Timeout={2}" -f $ServerName,$DatabaseName,$ConnectionTimeout
$conn.
ConnectionString=$ConnectionString
$conn.
Open()
$cmd=
New-Object system.Data.SqlClient.SqlCommand($Query,$conn)
$cmd.
CommandTimeout=$QueryTimeout
$ds=
New-Object system.Data.DataSet
$da=
New-Object system.Data.SqlClient.SqlDataAdapter($cmd)
[
void]$da.fill($ds)
$conn.
Close()
$ds.
Tables