Introduction to Windows PowerShell (Part1)

0

Windows PowerShell is a configuration management framework to perform administrative tasks.This tool is developed by Microsoft & available from 2006.This is one of the best tool for SQL DBA’s.It is a command line shell and associated scripting language.
There are so many sites availabe giving knowledge on powershell, I will not go on theory part.

Let’s hands-on Windows PowerShell-

PowerShell commands are verb-noun format. It also works as windows command prompt.

GoTo Start >> Type PowerShell then click Windows PowerShell (Or run it as administrator)

PowerShell

It is difficult to learn its all commands,So I always use help command to get all commands.It also support maximum DOS commands.

type help it will give you description about powershell.To get all commands type get-command

  • get-service
    • For getting service list
  • get-process
    • For getting process like task manager

Please try few more commands by yourself. Lets enhance our command writing with conditions-

Conditions- To apply condition Pipeline (|) is used in PowerShell.

Let we need the output of powershell command on a text file-

get-process | out-file <path>

get-process | out-file c:\Process.txt       or this command is also written as get-process | >C:\Process.txt

Some basic commands on PowerShell

In above image we can see different conditions on same command. format-table or ft used for table formating, -auto is used for adjusting table column size.

Last command contains few special characters like ?, $_ ……

? represent where clause, we can write either where or ?

$_ is Current Iteration. for looping we use for-each or %{<Command>}

So the last command in above image says get a service that contains sql word in its name where name of service equal to sqlwriter.

Now we want to stop this service so the command for this should be-

get-service | ?{$_.Name -eq “SqlWriter”} | %{$_.Stop()}

 

I am Microsoft Certified Professional for querying & Administering Sql Server. I believe “The greatest barrier to success is the fear of failure.”
I am also available at http://dbavimal.blogspot.com

  1. Rickey Thomos June 15, 2015 at 8:47 am

    Thank you Mr.Vimal. I am following you.

  2. […] Introduction to Windows PowerShell (Part1) […]

  3. Introduction to Windows PowerShell June 26, 2015 at 10:22 am

    […] Introduction to Windows PowerShell (Part 1) […]

  4. […] Introduction to Windows PowerShell (Part1) […]

%d bloggers like this: