PowerShell Step By Step (1): Basic Syntax

    When we touch an new concept which we never heard or know clearly, I think we should learn it by its help document especially for an new IT developer. Therebefore, let's start the trip from PowerShell basic syntax via PowerShell-Help, which you can find in the Windows PowerShell ISE via F1 .

    Windows PowerShell is a new Windows command-line shell designed especially for system administrators. The Windows PowerShell includes an interactive prompt and a scripting environment that can be used independently or in combination.

    Unlike most shells, which accept and return text, Windows PowerShell is built on top of the .NET Framework common language runtime (CLR) and the .NET Framework, and accepts and returns .NET Framework objects. This fundamental change in the environment brings entirely new tools and methods to the management and configuration of Windows.

    Windows PowerShell introduces the concept of a cmdlet (pronounced "command-let"), a simple, single-function command-line tool built into the shell.

    The Get-Help cmdlet is a useful tool for learning about Windows PowerShell.

    To display information about the Help system in Windows PowerShell, type:

  get-help
  get-help about_If
  get-help Get-Command get-date

    Variables

    Variables name starts with "$" sign. In PowerShell every variable can be treated as an object. As a scripting language, in fact, it is not so strict like C# or C++.

    Comments

    You can add code comments starting with "#". For example:

    # Declaring a variable

    $test=  "Hello World!"

    Input/Output

    Using command read-host/write-host to realize the input/output function in PowerShell

    $test = read-host "Please input your name"

    # `  here stands for escape character when you want to display the variable name

    write-host "`$test = "$test

    Functions

    Syntax of a function same as java, C#, C.

   # Declaring a function  below

    function MyFirstFunction()

   {

   # Function body

   }

    function MyFirstFunction

    {

    # Function body

    }

    function MyFirstFunction($test)

    {

    # Function body

    }

    # Calling function

    MyFirstFunction()

    MyFirstFunction

    MyFIrstFunction "Hello World!"

    In PowerShell, "$test" equals to $test.ToString(). If you just need to display the variable name in the string, then you have to user escape character `.

    Above just a simple introduction about PowerShell. Some are captured on the PowerShell-Help. Welcome to point at my mistakes. We'll continue to discuss about operators, cmdlets, and some key rules in the next blog

   

   

   

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章