Are you still using CMD?

Are you still using CMD?

CMD is a powerful well tested tool that I have appreciated and used often over the years. I believe I have used it for everything imaginable… I have used it for simple troubleshooting, automation, processing, etc. As useful as CMD is, it is time to move on. The question is, ‘Are you still using command exe for task related to your day to day activities?” If you are, now is the time to move on up to the power of PowerShell. PowerShell is a task automation framework, built on top of .NET Framework. PowerShell v1 was released in Windows XP and was an optional feature in later versions until Windows 7 / Server 2008 R2 in which PowerShell v2 is now integrated.
I want to encourage everyone to utilize PowerShell in place of CMD. By using it for your day to day activities it is an easy way to move from CMD to PowerShell and begin using the new features of PowerShell. To get started I have a few examples of routine task that I use regularly. I will not go into a deep dive of different object types, or parameters within PowerShell, I will leave that for you to discover on your own. These are basic task that I find easier and faster to do via PowerShell versus the GUI. So without any further delay let’s get started. These examples are simple, common on the job task that we in the database world perform regularly.

Is the instance up and running?
When unable to connect to an instance the one of the first things I want to know is the MSSQL Service running. We can launch SQL Server Configuration Manager, wait the time it takes to launch and take a look there. Or go to  Start  type PowerShell and select PowerShell. At the prompt type Get-Service *MSSQL*

NOTE: I am actually using PowerShell v2. During the upgrade, Microsoft decided it was not important to update the directory structure to reflect the v2.0 version.

Get-Service *MSSQL* returns the details for any service containing the letters MSSQL.

Simple using the Get-Service command returns a list of all services, with Status, Name, and DisplayName.

Here are a few format variations of the same Get-Service command.

Get-Service 2

Get-Service –NAME *MSSQL* | FORMAT-LIST DisplayName, Status will return the SQL Services Display Name, and Status properties in an easy to read format.
Get Service

So let us pretend that the service is not started. If the service is stopped then Start-Service %ServiceName% will start it. Stop-Service %ServiceName% will stop it. Restart-Service %ServiceName% will you guessed it… restart it.

The above commands are all simple commands that have equivalents in CMD, but they are also building blocks to help increase our knowledge and comfort level with PowerShell along with all the goodies that come with it.

Check out some of these online resources for more PowerShell. — Sign up for the daily PowerTip email. — lots of PowerShell examples — lots of tools and tips