Explore the basic operation of PowerShell (ii) PowerShell _powershell

Source: Internet
Author: User

PowerShell Console

Open PowerShell to display the following interface:

The command prompt prefix is:

PS c:\users\marui>

PS meaning is running PowerShell, and C: is my home directory drive letter, different machines will vary.

The most basic operation and CMD, DOS, SH and so the same.

Cmdlet command

Although more than 100 new PowerShell commands need to be learned, as with most command-line interfaces, the PowerShell command has been standardized. It uses the name form of "verb-noun" as a cmdlet command. This standard greatly reduces the difficulty of learning and provides better descriptive help for all cmdlet commands.

To view all the cmdlet in the current PowerShell, use the following command:

Get-command <enter>

Next, let's use a specific verb to list all the commands. The following is a cmdlet that is filtered using the verb "get":

Get-command-verb Get <enter>

Other commands can also use this filtering method. After this combination, hundreds of orders are well remembered.

Simple examples of other basic common commands:

Get-help <enter>

Get-help * <enter>

Get-service <enter>

Get-help Get-service <enter>

Try the following buttons to see what happens:

Page up-jumps to the first command in the history buffer.

Page down-jumps to the last command in the history buffer.

UpArrow-Displays the history buffer command backwards.

DownArrow-Displays the history buffer command.

Home-jumps to the beginning of the command line.

End-jumps to the ends of the command line.

Ctrl + Leftarrow-to leftmost character.

Ctrl + RightArrow-to the right word end.

tab-Complete input (type get-c in the console and press TAB, then press TAB to try).

F7 Key-Displays the history buffer (using the UP and DOWN ARROW keys to browse the buffer).

Or in another window copy a paragraph of text, on the PowerShell on the right mouse button to try, similar to the role of the mouse under the SH button.

In the PowerShell command, there is also a class called "native window commands." For example, we can start the GUI window of services.msc from the PowerShell command line.

Services.msc <enter>

Since we use PowerShell, we can ignore services.msc.

The following are the commands to operate the service < take Brower services as an example:

Get-service-name Browser <enter>
Stop-service-name Browser <enter>
Get-service-name Browser <enter>

Note that there is no indication that the service has stopped successfully when you use the cmdlet to stop the service.

Similarly, start the service command:

Start-service-name Browser <enter>

When the service is started, there is no feedback that the service will start properly unless the service fails to start.

This paragraph of the order is simply introduced here, is not very simple? Just remember to "verb-noun" this form is OK!

The following is a sample of the basic operation syntax in PowerShell

PS c:\> 99 + 100
199

In the PowerShell, can be very simple to do the math, you have to do is only the input expression so simple, the results will be automatically output, in this process does not need to use other shell print statements, etc., the operation is finished after the execution results will not be arbitrarily discarded, but direct output, In the future we will learn how to discard the results.

PS c:\> "Hello world!"
Hello world!

"Hello World", just like the math above, just enter the string. Perl scripts have been used to find this familiar, because PowerShell largely borrows from the advantages of Perl.

PS c:\> (7-2 * 3)/5
0.2

For four hybrid operations, PowerShell can also be well supported. You can use () in an expression to adjust the precedence and binding of operators. It should be noted that PowerShell supports several different data types, such as int, float, double, and so on. In the future we will be exposed to the type conversion and so on.

PS c:\> (2+2) *3/7 > C:\fun.txt
PS c:\> Type C:\fun.txt
1.71428571428571

Also, in addition to the screen output, we can store the results in a temporary file and then use the type command to retrieve the results of the file.

PS c:\> $n = (2+2) *3
PS c:\> $n
12
PS c:\> $n/7
1.71428571428571

In addition, we can also assign a value to a variable, store the result of the operation in a variable, and use that variable for subsequent computations.

PS c:\> $files = Dir
PS c:\> $files [3]

PS c:\> $files = Dir
PS c:\> $files [3]
Directory:microsoft.powershell.core\filesystem::c:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
d-r--2010-3-26 21:25 Program Files

As an object-oriented language, we can simply assign the result returned by the command to a variable. The $files here contains a collection of objects for the directory entries in the current directory, and the normal array access syntax allows you to get the object at that location. The Program Files directory is shown in the example. Note: The array subscript in PowerShell starts at 0, which is exactly the same as the. Net Common Language Runtime.

This is the first section. Interested children's shoes can continue to focus on the next section.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.