Showing posts with label Powershell v2. Show all posts
Showing posts with label Powershell v2. Show all posts

Tuesday, January 27, 2015

PowerShell : 3 Cool tips to learn PowerShell.

 

6:30 am in the morning and my phone starts ringing……

I picked up the phone and I heard the familiar voice, it is  “A Murky Ana!”

A Murky Ana : “Are you sleeping?”

Me : “Nope, was playing soccer, at 6:30 am. Come On! what peoples does at 6:30 am in the morning? They do sleep.”

A Murky Ana: “OOps, sorry to wake you up, I have a question.”

Me: “What!!!! Can’t you ask a question after 4 hours, so that I can complete my sleep ( yawning) ”

A Murky Ana: “No! answer me now!”

Me : “{… thinking.. W.T.Heck} ,  OK, give me 3 minutes, let me make Coffee first? Can I hung up the phone can call you back?

A Murky Ana: “No! I can hold “

Me : “OK, OK”

I started making coffee and after that we started the conversation again…

Me: “Ok, what is your question?”

A Murky Ana:After talking with you week before ,  I am interested in Learning PowerShell, I want to know the tips to learn PowerShell”

Me : “Ok, Pick a Pen and write  down the tricks which i am sharing with you now.”

A Murky Ana: “ Done”

Me : “ I am giving you 3 cool tips to learn PowerShell easily and quickly”

Tip 1 :  “Start using PowerShell Console, rather than “CMD”

 

You can run the native windows command on “PowerShell Console” too, PowerShell console do support most of the in-built native command, So start using the PowerShell console to get familiar with it, to know more about it’s look and feel. Stop using the CMD. You can do the same thing which you do on cmd, it's time to replace CMD with PoweShell console.

 

27-01-2015 18-27-44

TIP 2 : “Start using PowerShell Cmdlets rather than “native commands”

 

The more you use PowerShell cmdlets and the more you learn PowerShell. You can start using some basic PowerShell cmdlets and stop using the native ones. For example start using Test-Connection rather than using Ping.exe to below is the list of few command which you can use rather then the native ones.

 

Replace

With PowerShell Cmdlet

Ping

Test-Connection

Dir

Get-Childitem

Mkdir

New-Item

Cat

Get-Content

Tasklist.exe

Get-Process

Shutdown /r

Restart-Computer

net start

Start-Service

net stop

Stop-Service

 

 

 

Tip 3: “Make a new friend “Get-Help”

 

Start learning about PowerShell, the best way to learn is to start reading the ABOUT files. They have contain information about most of the PowerShell features and techniques.  Read a About file in a day and that make your PowerShell learning easy and fast.

PS C:\> Get-Help *about*

27-01-2015 19-07-59

A Murky Ana: “That’s Cool. Ok I give a try and let you know, Bye!!!!!!!”

She hung up the phone……………………………..

 

* All characters appearing in this work are fictitious (Apart from ME and the Author of the books and the online reference on the blogs). Any resemblance to real persons, living or dead, is purely coincidental.

 

Regards.

Aman Dhally
If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.

Tuesday, April 23, 2013

Powershell Script : Stopwatch

Hi,

Few days back I upload a script on “Powershell Digital Clock”, when i was writing that script at that time another script idea strike in to my mind, that ideas was to create a Stopwatch using Powershell.

I don’t know writing a script for stopwatch is a good idea or not, but i know one thing that i will learn a new thing and that may be helpful in the future.

After thinking i started writing an GUI based script to creating a stopwatch.

Powershell has open lots of possibilities for system administrators like me. We just need to imagine what we want and we able to achieve it easily using Powershell.

Last week when i take a session in Delhi User Group meeting, i told attendees that Powershell is the most easiest scripting language to be learn.

Anyway.

In this “Stopwatch” i used 4 buttons, one to start the clock, One to stop the clock , one to reset the stopwatch and another is for the lap.

I am not so good in designing GUI so ignore the colour of the buttons ;o).

In this script i learn few new things.

Lesson Learned:

  • System.Diagnostics.Stopwatch class
  • Few methods of System.Diagnostics.Stopwatch class
  • Make multiline textbox in powershell to auto scroll using
              • $textBox1.SelectionStart = $textBox1.Text.Length;
                $textBox1.ScrollToCaret()

  •  

23-04-2013 22-51-47 23-04-2013 22-55-52  

“Screenshot of the script”

Please run this script in –Sta mode

23-04-2013 22-54-51

Download Link : https://dl.dropboxusercontent.com/u/17858935/StopWatch-Community-Edition.zip

 

Thanks
Aman Dhally
 
 
clip_image001 clip_image002 clip_image003 clip_image005clip_image007

Tuesday, April 2, 2013

using Get-Location cmdlet in PowerShell.

Hi everyone.

Sometime, while using our regular or favourite cmdlets, we often forget to use non-regular, non-common cmdlets. When you look in to all cmdlets which powershell offers, you can see there may be few cmdlets which you never used and never notice them.

One of the cmdlet which i came to know is “Get-Location” whose alias is “pwd” (present working directory)

As its name defines , when you run it, it shows your location (not GPS one :D ), it shows you that  in which folder you currently working in.

02-04-2013 17-47-37

this cmdlet is very useful when you want to record you current folder location in to the powershell scripts.

This cmdlet has three main properties.

  1. Path
  2. Drive
  3. Provider

To check these properties we can put Get-Location in to a variable.

$location = Get-Location

02-04-2013 17-49-34

to know the path of the current location we can type $location.Path property.

02-04-2013 17-49-45

To know the name and other information, we can use $location.Drive property.

02-04-2013 17-49-57

to know the PS Provider type, we can use $location.Provide property.

02-04-2013 17-50-11

That’s all for now. :)

Thanks
Aman Dhally
 
 
clip_image001 clip_image002 clip_image003 clip_image005clip_image007