Thursday, April 16, 2009

First Powershell Script

Windows Powershell is another attempt from Redmond to provide powerful windows scripting language to IT professionals. But this time, I would say that it is a successful attempt by Microsoft.

Windows Powershell is often being compared with Unix Bash Shell. But it actually does more than what you may expect. Unlike its Unix counterpart, the PowerShell pipeline is an object pipeline; that is, the data passed between cmdlets are fully typed objects, rather than byte streams. A cmdlet, pronounced "command-let" is same as what you call "shell script" in Unix. So don’t get confused with cmdlets

I have read more reviews on Powershell and excited to see Powershell in action. I'm posting all my learning as I learn so it could be useful to everyone.

Click here to download Windows PowerShell 2.0 Community Technology Preview (CTP)

So Here is your first simple “Hello World” script:


PS C:\Documents and Settings\jagadish.g> Write-Host "Hello World"
Hello World
PS C:\Documents and Settings\jagadish.g>

Write-Host cmdlet is similar to echo in Unix. You can specify separator, background color, foreground color and more.


PS C:\Documents and Settings\jagadish.g> Write-Host (10,10,12)
10 10 12
PS C:\Documents and Settings\jagadish.g> Write-Host (10,10,12) -Separator "+"
10+10+12
PS C:\Documents and Settings\jagadish.g> Write-Host (10,10,12) -Separator "+" -ForegroundColor Green -BackgroundColor Black
10+10+12
PS C:\Documents and Settings\jagadish.g>


Now we will go through some simple cmdlets.

Get-Process
    Gets the processes that are running on the local computer or a remote computer


PS C:\Documents and Settings\jagadish.g> Get-Process | Select-Object -First 3

Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
------- ------ ----- ----- ----- ------ -- -----------
32 2 780 2708 28 0.05 1296 acrotray
107 5 1168 3524 32 0.03 2712 alg
203 7 3584 6648 43 0.36 3724 btdna

PS C:\Documents and Settings\jagadish.g>

Get-Service
    Gets the services on a local or remote computer


PS C:\Documents and Settings\jagadish.g> Get-Service | Select-Object -First 3

Status Name DisplayName
------ ---- -----------
Stopped Alerter Alerter
Running ALG Application Layer Gateway Service
Stopped AppMgmt Application Management

PS C:\Documents and Settings\jagadish.g>


If you have any questions on Powershell, please post them in the below comments section

5 comments:

  1. Hi Jagadish,

    I am new to this power shelll can i have any doc/pdf to learn from the scratch.Please send me to this id-->iampraveen6@gmail.com


    thanks
    praveen

    ReplyDelete
  2. Praveen,

    I have sent you some pdf documents for your refernce

    Best of luck !

    ReplyDelete
  3. Hi Jagdish You are right that Windows Powershell is powerful windows scripting language to IT professionals.The example you provided here is simplest.Can you share some links for study related to this

    ReplyDelete

  4. Your blog is very useful for me.I really like you post.Thanks for sharing.
    goldenslot
    gclub casino

    ReplyDelete
  5. World-class casinos The mind of the player as well.
    viva9988Is a web g club One of the world's leading online gambling houses, the world's leading online gambling provider, is thriving online gambling that is free of thought and imagination. The system of online casino web site. A new system that allows gamblers to access and play online gambling in all forms, just dare to open your mind to play online gambling games only, risky people can join the fun and challenge. Efficiency in Online Gambling Betting on GClub Website Our online casinos and online gambling games offer you more fun. Since every time you beat online casino games, you can make money from playing online gambling games there. The fun of playing online gambling games happens whenever you can beat online gambling. Every time a risky player wants to play online gambling games. Do not forget to choose our online casino site for great fun channels, open 24 hours a day, when you want to play online gambling games simply by clicking the web. จีคลับ

    ReplyDelete