官术网_书友最值得收藏!

Understanding PowerShell syntax

Windows PowerShell uses a verb-noun pair as a naming system. The name of each cmdlet includes a standard verb hyphenated with a specific noun. Verbs are used for specific actions in Windows PowerShell, and nouns are used to describe objects by users and system administrators. Here are some of the examples that show how little effort is required to work with cmdlets, and one does not have to memorize them.

Nouns in a cmdlet describe what the cmdlet will act on. For example, get-process, get-service, stop-process and stop-service. If this is used regularly, one can get to know the standard set of verbs and nouns used in PowerShell. With these verb-noun pair, hundreds of cmdlet names can be remembered and used.

You will be able to recognize the operation performed by a cmdlet by just reading the name as it is mostly apparent about the name used by a new command should relate to the operation. For example, get-computer will give you a list of computers on your network. Get-date and get-time will display the system date and time respectively. Similarly, stop-computer will shut down a computer. Set-date and set-time will set the system's date and time.

Let's look at how to list all the commands that have the particular verbs called Get and Set using Get-command with the –verb parameter. The output of this command is piped to display in a table format (more on this will be covered later in the Usage of pipelines section).

In the next example, we will just use instead of a format table:

Now, let's use the -Noun parameter, and we will find a list of commands that affect the same object type. For example, if you want to see commands that are available for managing computers, type the following command:

Traditionally, the commands in the earlier shells usually do not have a consistent parameter name. Sometimes, they don't have a name at all, and even if they do, they are abbreviated to make typing easier. But, this makes it difficult for new users to understand the parameters that are used. In Windows PowerShell, consistency is encouraged by using developer guidance on the usage of parameter names.

The names of the parameters in Windows PowerShell have a hyphen '-' prepended to them to allow PowerShell to demarcate them as parameters. In the get-command –Noun example, the name of the parameter is Noun and is typed as –Noun.

The cmdlets in Windows PowerShell support several common parameters as the PowerShell engine controls these parameters. So, no matter how they are implemented, they will behave in a similar way. Another way to drive the consistency and learning of Windows PowerShell are some of the common parameters like—Confirm, WhatIf, outvariable, warningaction, warningvariable, debug, and verbose.

主站蜘蛛池模板: 阳西县| 石家庄市| 绥江县| 万安县| 通城县| 石家庄市| 兰坪| 峨山| 祁东县| 庆云县| 邳州市| 赤峰市| 商洛市| 蓬安县| 潜江市| 海淀区| 江门市| 铜山县| 北川| 泌阳县| 甘德县| 益阳市| 辽阳市| 乐至县| 南投县| 安庆市| 枞阳县| 安远县| 乌什县| 公安县| 唐山市| 信宜市| 承德县| 团风县| 吉木萨尔县| 托克托县| 寿宁县| 颍上县| 巨野县| 闵行区| 平原县|