• 1. Introduction to Powershell

    Posted on January 29, 2013 by in Desktop Engineering, Powershell, Scripting

    What is Powershell?
    PowerShell is a new command shell from Microsoft and yes it is a command prompt and scripting environment, it can even be both at the same time. Windows PowerShell is an extendable command shell and scripting language which can be used to manage/administer server environments like Windows Server, Exchange and also SharePoint etc.

    PowerShell is object-based not text-based
    This concept will take a little time grasp for dos/cmd.exe and batch script writers. Those using VBScript and other programming languages already understand the concept. The basic difference, traditional command prompt output is text-based while output in PowerShell is not. It looks like text but it is actually an object. Why is this powerful? Because the output of a PowerShell command (the object) can be piped into another command without additional programming. With traditional scripting, if you wanted to use the output of one command in another, additional programming would be required to manipulate the data in a format the second command could understand. What is an object? This should sound familiar to the Windows Administrators out there… “Everything in an Active Directory Domain is an object.” Servers, Computers, Printers, Shares, Organizational Units, Security Groups, Group Policy Objects, Users, etc… With PowerShell we can interact with these objects to enumerate information (object-properties) and/or create, modify, or delete objects and/or object-properties (object-methods).

    PowerShell Commands are customizable
    PowerShell commands are referred to as Cmdlets. With the installation of PowerShell there are over a hundred cmdlets for you to get up close and personal with. The PowerShell team, in their infinite wisdom, created aliases to allow us to use the traditional commands we have become accustomed to (dir, cd, del, copy, etc…). Even the UNIX guys get a break with provided aliases (ls, man, etc…). PowerShell allows you to create your own aliases as well as creating your own cmdlets. Yep, unlike dos/cmd and reskit exe’s, PowerShell provides a method to create your own PowerShell cmdlets.

    PowerShell is a Command line interpreter and a scripting environment
    In a nutshell you have the best of both worlds within PowerShell. DOS was a command line interpreter, enter command get output. Sure you could use batch files, but in reality a batch file just entered the commands for you. VBScript utilizes WSH (Windows Scripting Host); you can’t enter VBScript code in a command prompt. With PowerShell not only can you enter commands, you can build script-blocks from the PowerShell command line. You will be doing this in later tutorials.
    Powershell is included by default in windows7 and Windows8 client operating systems.
    Download powershell from here http://www.microsoft.com/en-us/download/details.aspx?id=34595
    and install.

    Launch Powershell Console

    launch PowerShell from a command prompt or in start -> run by simply typing powershell


    You will notice the command prompt PS H:\myprofile\MyScritps>
    PS signifies that you are running PowerShell.H:\myprofile\MyScritps> is the default directory that is specifed to run powershell.
    Lessson 1: Customize the powershell Console.

    As you have noticed my prompt points to H:\myprofile\MyScritps>. I like to organize my scripts in one location where I can access them quickly. H: is a drive mapping to my home directory on a file server. In this exercise we configure the PowerShell Console to open in a directory called “MyScripts.”

    1. Create the following directory – H:\myprofile\MyScritps>
    2. Create a PowerShell shortcut on your desktop.
    3. Right-Click on the shortcut and choose Properties.
    4. Under the Shortcut tab locate the Start in: text box. Type in the path to the folder created in step 1. H:\myprofile\MyScritps>
      Click Ok.
    5. Launch PowerShell from the desktop shortcut. 

    Feel free to choose the directory path of your choice. If your path has a space in it, don’t forget to double-quote it. Example: “C:\Program Files\MyScripts.”

     Customizing color and text-size

    1. Right-click on the shortcut and choose Properties.
    2. Choose the Colors tab.
    3. You will see four radio buttons; Screen text, Screen background, Pop-up text, and Pop-up background. The Screen buttons are self-explanatory; the Pop-up buttons are for colors used in the History Buffer.
    4. Set Screen text to yellow, Screen background to red.
    5. Launch PowerShell from the desktop shortcut.

     you can play with Font and colors from the Powershell properties tab

     

    Keyboard shortcuts that are used in Powershell

    1. Page Up – Jumps to the first command in the history buffer.
    2. Page Down – Jumps to the last command in the history buffer.
    3. Up Arrow – goes back one command in the history buffer.
    4. Down Arrow – goes forward one command in the history buffer.
    5. Home – Jumps to the beginning of the command line.
    6. End – Jumps to the end of the command line.
    7. Ctrl+LeftArrow – goes to the left one word at a time.
    8. Ctrl+RightArrow – goes to the right on word at a time. 
    9. Tab – Completes input (in the console type get-c and press tab, press tab again…).
    10. F7 – Shows history buffer (use the up and down arrow keys to navigate the buffer).

     

     

     

    Be Sociable, Share!
      Post Tagged with

    Written by

    Senior Desktop/Infrastructure Engineer with over 10 years of proven experience in planning,designing & implementation of enterprise level Workstation builds for Finance, Pharmaceuticals, Telecommunication and other Domains. Desktop Engineer cannot rest as, Desktop world is very different it is fast paced, new technologies evolve and change at a rapid pace. For more info please visit: www.linkedin.com/in/srinivaskolla

    View all articles by

    Email : [email protected]

    Leave a Reply