July 11, 2008

21 characters to paradise

Powershell gives SQL Server a huge boost

I've been playing with Powershell off and on for about a year, but I was never really very serious about it. But this year at TechED I spent some time looking at the new powershell features in Katmai and what can I say... I'm officially in love. No, wait a minute... this is melting hot lust.

Let me just say that the way the powershell provider in Katmai has been implemented as a minishell has come under some criticism. And maybe they have a point. There are some thing you can't do, and I'm not going to go into those as they're all very well documented in different blogs. What I am going to go into is what you CAN do with powershell in SQL Server. That's right, I said SQL Server, and not just Katmai. Because you can connect to any Yukon or SQL2K box and run powershell against them. I think there are some prereqs there like SQL2K SP4 and maybe SQL2K5 SP1, but you can look that stuff up yourself. The point here is that you're not limited to Katmai.

OK, so rather than spend lots of time talking you through little things, I'm just going to give you a couple examples here.

To list all tables and their rowcounts:
Open powershell in SSMS and type the following: I'm using Northwind.

cd default\databases\Northwind\tables
So just like in DOS you navigate DB structures like drives.

Now type:
gci | sort-object -Property RowCount -desc | format-table Schema, Name, Rowcount -autosize

In short, I'm getting all the tables, sorting them by rowcount in descending order and then piping the output to a table with the Schema, Name, and RowCount columns. And autosize just tightens up the table size. Try this command with and without the -autosize parameter and you'll see what I mean.

So that's pretty cool right? You can get all the tables and their rowcounts w/o a cursor or dynamic SQL or a #table. Now, let's filter a little bit. The same command comes back...

gci *customer* | sort-object -Property RowCount -desc | format-table Schema, Name, Rowcount -autosize

Now you see the same command with *customer* in it. This tells it that you only want tables that have 'customer' in them. So in SQL this is equivalent to "like '%customer%'".

So far so good?

OK, one more because this one is just tremendous.

Start in the same location as before:
For completion, you'll be here:
cd default\databases\Northwind\tables

Now type this:

gci | % {$_.Script()}

White Paper

D2D Virtual Tape Library Replication Primer

This whitepaper explains the terminology and concepts behind Data Replication technologies and establishes some sizing rules through worked examples. Learn the new paradigm in disaster tolerance—protect data anywhere.

Download now »

White Paper

An Alternative to Virtualization for Datacenter Cost Savings

Server virtualization is a popular option for dealing with mounting datacenter costs. Another equally promising approach is the use of an Application Delivery Controller. Citrix NetScaler provides a low-cost way for organizations to reduce their server count and accrue cost savings from a reduction in space, cooling, power and personnel.

Download now »

White Paper

Why Your Firewall, VPN, and IEEE 802.11i Aren't Enough to Protect Your Network

The emergence of WLANs has created a new breed of security threats to enterprise networks.

Included in HP ProCurve WLAN solutions is security technology that alleviates threats from WLANs through:
* Monitoring wireless activity inside and out of the enterprise
* Classifying WLAN transmissions into harmful and harmless
* Preventing transmissions that pose a security threat to the enterprise network
* Locating participating devices for physical remediation

Download now »

White Paper

Bringing the Edge to the Data Center

Effectively address data protection challenges, implementing solutions that help store and protect business–critical data while cutting costs and improving efficiency and reliability.

Download now »

Sign up to receive InfoWorld Resource Alerts

Subscribe to the Today's Headlines: First Look Newsletter

Find out what will be news for the day, with our first-thing-in-the-morning briefing.

©1994-2009 Infoworld, Inc.