PowerShell

PowerShell + MySql

Today, doing one small task I thought: “Why can’t I do it with PowerShell?”
So, here is a small example:

[void][system.reflection.Assembly]::LoadFrom("c:\devel\mysql\ps\MySQL.Data.dll")

$myconnection = New-Object MySql.Data.MySqlClient.MySqlConnection
$myconnection.ConnectionString = "server=localhost;user id=test;password=test;database=test;pooling=false"
$myconnection.Open()

$mycommand = New-Object MySql.Data.MySqlClient.MySqlCommand
$mycommand.Connection = $myconnection
$mycommand.CommandText = "SHOW TABLES"

$myreader = $mycommand.ExecuteReader()

while($myreader.Read()){ $myreader.GetString(0) }

--
c:\devel\mysql\ps\MySQL.Data.dll - that is a connector

PowerShell is a quiet new thing, so I believe it could be helpfull.

Starting with PowerShell

Windows PowerShell requires .net-2.0 framework, so you should have it. Whole PowerShell package weights about 1.5Mb, and it is a very small size for application with such functionallity.
First of all you should become familiar with command ‘help’. It is similar to wellknown ‘man’, and ‘man’ alias also exists. To get full information about any command you can with ‘help command-nme [-detailed | -full]’.
Parameter -detailed is similar to -full, but it does not show you notes and additional command input/output parameters information.

Remembering my linux experience I wanted to have anything similar to ‘ps’. And, yes, we have it - command ‘Get-Process’. But this is not very handy and we have alias for ‘Get-Process’ called ‘ps’. So executing the following:

ps | sort cpu -descending

we do:

Get-Process | Sort-Object cpu -descending

Windows PowerShell ps command

We can set and modify aliases, for example:
Set-Alias myps Get-Process

ps For first look PowerShell has very pretty good logic, and for my opinion is more flexible and modern than any Unix shell.

PowerShell, I believe in it

What an ugly thing DOS command line is, and how great Linux/Unix command line is. And Microsoft knows that is a thing a lot of users are dreaming about, it would be cool even if a part of Linux/Unix command line functionallity will be implemented. However, already exists such tool! And it named PowerShell

. Its aim is to make our life better. I knew about it just some hours ago, anyway, will use it, learn it. I hope this will cure my sadness on Linux :)

And in following
Weblog you can read and comment PowerShell developers thoughts.