Saturday, September 19, 2009

DBA’s & PowerShell? Yep, PowerShell is not just for your IT brethren, you can have PS fun too!

The SQL Snapshot - PowerShell 101 for the DBA: Querying Your Servers with PowerShell

“In my last blog post, I discussed how to get PowerShell and SQLPS up and running on your machine(s). And much like my dog chasing its tail, you’re probably asking yourself, “Now that I have it, what do I do with it?”

The first thing you’ll want to learn is how to actually connect to, and get information about, your servers. So, go ahead and go to your Start>Run or Start>Search box and type SQLPS. If everything is installed correctly, you should see:

Alright, let’s start off with looking at the SQL Server services running on a given machine. Use the cmdlet “get-service” to find out about services on either your local or a remote machine. This is not a SQLPS specific command, but rather a PowerShell command:

When run, this command returns no output to the command line screen, but dumps the file to the specified directory. Using this method will get you a slightly more usable list of rows to review. Again, use get-help invoke-sqlcmd to get more info.

At this point, you have enough information to be dangerous! Be sure you’re careful when querying any production servers, because if you have the right credentials, you could do a lot of damage. In the next post, I’ll talk about how to create scripts using basic PowerShell and SQLPS cmdlets that access system objects in SMO and Windows. Until then, have fun!”

Just this week, I’ve finally been given the “go” to start moving to moving my product to SQL Server 2008 (sigh… It’s a long story). While this is going to be a 6+ month project (not due to any technical reasons… you guys know the deal… another sigh), at LEAST it’s moving forward! [Insert “Two steps forward, X.x back] whine here… okay, that’s enough whining… ;]

This means my mental “SQL Server 2008” key will be more active and so I’ll likely be capturing more related articles, like this one.

Personally, I have to start using PowerShell more. It’s THE Windows command line, with power that’s hard to believe. As I might of said in the past, PS IS the future. Now I just need to get off my butt, rise above and move outside my comfort zone jump into it. (sigh… so much easier said that done… LOL )

BTW, if you’re new to PowerShell also check out, The SQL Snapshot  - PowerShell 101 for the DBA – Installing PowerShell.

(via Alvin Ashcraft's Morning Dew - Dew Drop – September 18, 2009)

 

Related Past Post XRef:
PowerShell and SQL Server 2008 Whitepaper
More details about SQL Server 2008 and its PowerShell support
SQL Server 2008 & PowerShell - Better Together
SQL Server Provider/Namespace for PowerShell (Think "Easy Command Line/PowerShell Access to SQL Server Data")

No comments: