I just wrote an article at Simple-talk.com about a secure and flexible method for perfmon…
“There are many roads you can take in the forest,” my grandma would say. And by this she meant that you can achieve the same goal in many different ways. And it is true. You can take a dangerous shortcut or the scenical route and at the end you will still get to the same point. I am mentioning this, because I would like to make a cheap analogy with SQL Server. Here is how: in SQL Server, as we know, there are many ways to achieve the same goal; let’s say we are interested in some performance counters, some database size or server settings. In order to obtain the information, we can use wide range of tools: T-SQL query, built in reports, Perfmon, and so on. What happens if we need to ask the same question to 2 servers? Or 10 servers? Or 100? Well, here are a few ways to do it:
– open SSMS and connect to each an every one of the servers, and execute a T-SQL
– if you are lucky enough to have one of your servers as SQL2008, then you can spend some time setting it up as a CMS (central management server) and query all servers at the same time
– you can develop a SSIS package which collects the data for you by iterating through a loop of defined SQL Server connections
– you can write a C# application which also loops through given set of connection and fulfills your request
Yes, but I need the information today! I need it now! 🙂 PowerShell seems to be a great answer to this challenge. Here are several reasons why I would take this road
– PowerShell is as simple as “text based automation solution”
– everything in owerShell is an object and every object has properties which can be invoked and piped (passed to other objects)
– there are great tools like PowerGUI, which give intellisense, debugging mode and real-time explaination of objects / cmdlets
– it helps me improve my grasp of SMO and WMI in order to manage the servers in more efficient way
I hope not to get in some copyright trouble with the Arla cow, but his is really how I see PowerShell in action. 🙂 It runs fast, in a one line code we can get information which otherwise would be retrieved by long T-SQL Statement; it is COOL.
I recommend that every DBA acquires the PowerShell as a skill. For further details look at Ron Dameron’s blog post, which contains plenty of examples of PowerShell uses.
My favorite scripts, however are the following 3:
How to parse the error log: Get-eventlog System | Where-Object { $_.entryType -eq “error” }
How to get continuous performance counters (this is new to PS 2.0): Get-Counter ‘Processor(*)% Processor Time’ -Continuous
How to get disk sizes for several remote servers: Get-WmiObject -Class Win32_LogicalDisk -Filter “DriveType=3” -computername “server1″,”server2”, “server3”