You are here:   Home > Sql
Register   |  Login

Programmer Newsletter

Minimize

Master Programmer

Minimize

Find articles on computer software, programming, ASP.net, Sql server, databases, C#, websites, Internet, Windows, Outlook macros.

Programming Articles

Minimize
23

Open Sql Server Management Studio (express version works).

Click on databases, click on a database, right click on Tables, click Start Powershell.

1. You can run Powershell from your start menu or command prompt. You will need to load the SMO library. At the Powershell prompt, enter this.

[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")

Connect to local host

$sqlServer = new-object ("Microsoft.SqlServer.Management.Smo.Server") "(local)"

Run some commands to see  what you get.

$sqlServer | get-member | MORE
$sqlServer.Properties | MORE

2. SQL Server 2008 includes a cmdlet named Invoke-Sqlcmd, which provides capabilities similar to the SQLCMD command-line tool. When you install SQL Server 2008, you can access PowerShell with the Sql libraries loaded. 

C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLPS.exe

SQLPS is PowerShell 1.0 with the SQL Server 2008 libraries added.

If you launch Windows PowerShell 1.0, the SQL Server 2008 tools will not be available; you can install them by issuing the following commands in PowerShell:

add-pssnapin sqlserverprovidersnapin100
add-pssnapin sqlservercmdletsnapin100

PowerShell has built-in documentation. To get the details on the Invoke-Sqlcmd cmdlet enter the following command in PowerShell.

get-help invoke-sqlcmd -detailed

By Andrew Weitzen, Bronze Inc. (c) 2010

Bronze is the publisher of several online Internet journals including: InternetHandholding.com, DomainNames.gs, DotNetNuke.bz, Programmer.bz, Software.vg, WebHosting.vg

www.mssqltips.com/tip.asp?tip=1684

Posted in: PowerShell

Post Rating

Comments

There are currently no comments, be the first to post one.

Post Comment

Name (required)

Email (required)

Website

Programmer Newsletter

Minimize

Subscribe to the Internet Handholding newsletter



Reccomend Programmer.bz

Minimize

Share/Bookmark Bookmark and Share