PowerShell Step By Step (1): Basic Syntax

本文将带领您从Windows PowerShell的基本语法开始,通过使用PowerShell-Help功能,逐步了解这一专为系统管理员设计的强大命令行外壳。文章涵盖了变量、注释、输入/输出、函数等关键概念,并提供了简单的介绍。
摘要由CSDN通过智能技术生成

    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

   

   

   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值