Random header image... Refresh for more!

Archive for the ‘SQL’ Category

Another Handy SQL function in PowerShell

Icon Written by Niklas Goude on January 30, 2009 – 12:29 pm

The Get-SQL function retrieved data from SQL and presented it in a HashTable Array.

Let’s create a similar function that we can use when updating, inserting or deleting data from an SQL server.

function Set-SQL ([string]$Query,[string]$ConnString) {

if ($ConnString) {

if($ConnString -match ‘”*”‘) {
$ConnString = $ConnString.TrimStart(‘”‘)
$ConnString = $ConnString.TrimEnd(‘”‘)
}

} else {

# Default ConnectionString
$ConnString =
“server=SQL;database=master;trusted_connection=true;”

}

$Connection = New-Object System.Data.SQLClient.SQLConnection

$Connection.ConnectionString = $ConnString
$Connection.Open()

$Command = [...]

Tags:

Handy SQL Function in PowerShell

Icon Written by Niklas Goude on January 27, 2009 – 10:20 am

In a previous post I described a little about PowerShell and SQL, how to connect and how to handle different queries through PowerShell.

Now let’s put it all togheter and create a more handy function.

function Get-SQL ([string]$Query,[string]$ConnString) {

if ($ConnString) {

if($ConnString -match ‘”*”‘) {
$ConnString = $ConnString.TrimStart(‘”‘)
$ConnString = $ConnString.TrimEnd(‘”‘)
}

} else {

# Default Connection String
$ConnString =
“server=ServerName;database=DbName;trusted_connection=true;”

}

$Connection = New-Object System.Data.SQLClient.SQLConnection

$Connection.ConnectionString [...]

Tags:

SQL through PowerShell

Icon Written by Niklas Goude on January 26, 2009 – 9:29 pm

Working with Databases through PowerShell can be a little tricky since PowerShell doesn’t contain any SQL CmdLets. Let’s start connecting to our SQL database using the SQLConnection object:

PS > $Connection = New-Object System.Data.SQLClient.SQLConnection
PS > $Connection

StatisticsEnabled : False
ConnectionString [...]

Tags: