PS
Powershell Tutorial Online

SQL-Management-Studio-Startup-Script

We will be adding powershell script and description soon.

Our code is self explaintory, I will explain or add my comments in detail as time allows me.

$dataSource = "." # localhost/ SQL Server instance name
$user = "sa"
$pwd = "sa"
$database = "Test";
$connectionString = "Server=$dataSource;uid=$user; pwd=$pwd;Database=$database;Integrated Security=False;"
$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = $connectionString
$connection.Open()
$query = “SELECT * FROM Employee”
$command = $connection.CreateCommand()
$command.CommandText = $query
$result = $command.ExecuteReader()
$table = new-object “System.Data.DataTable”
$table.Load($result)
$format = @{Expression={$_.FirstName};Label=”FirstName”;width=50},@{Expression={$_.FirstName};Label=”LastName”; width=50}
$table |  format-table $format
$connection.Close()