Powershell_ 0 Basic Self-study course _1_ first Knowledge PowerShell

Source: Internet
Author: User
Tags aliases

Welcome to reprint this series of articles; reprint please specify Source: Www.cnblogs.com/volcanol

Since Microsoft launched. NET, Microsoft's Windows system has undergone a great change, first of all, the operating system interface changes, such as Vista and XP interface changes,

Next is some application changes, for example, under the XP does not have the Aero desktop effect, but under the Win7 has the Aero desktop effect (I did not use Vista, did not know has the aero effect).

But these are the intuitive feelings of the user, in addition to these more profound changes, such as the C + + CLR and CLI, and some of the most popular technologies (such as WPF, WCF and what

Workflow and so on, these I do not understand, have only heard of these); Here is another change from these changes: console shell changes.

The main scripts under XP are: VBScript, JavaScript, and Batchfile batches, which are powerful and often have unexpected effects; for example, before I

Two days. The batch that removes the leading number of code. After Vista, Microsoft developed a new console Shell--powershell for Windows.

I. Features of PowerShell

1. Compatible with standard Windows commands and applications

2. New command format: cmdlets

3. Object support/Object-oriented

4. Suitable for administrator application

5. Multi-lingual support

6. Discovery function: Get-command, get-help, Get-member command

Second, start PowerShell

1. cmd-—— > PowerShell

2. Start-->all program--> accessories-->windows powershell-->windows PowerShell

The post-boot interface looks like this:

Three PowerShell Foundation

3, 1 How to execute the program/command

1) Directly enter the command or program name to execute the program or command

Exp:

Program.exe arguments

SCRIPTNAME.PSL arguments

Batchfilename.bat/cmd arguments

2) command to run a command containing spaces, enclose the command in single quotation marks, and precede the command with: & symbol; This is called Invoke operation in PowerShell

(Invoke Operator)

Exp:

& ' C:\Program files\program\program.exe ' arguments

3) Run the command or program under the current directory or path

This, PowerShell draws on the experience of Linux/unix, when executing a program or command under a non-system path in PowerShell, you must explicitly specify the command

or the path to the program.

Run the current directory or the command under the path or the program is implemented by adding: ". \" before the command.

Exp:

. \program.exe arguments

4) Run the current directory or the path, the command or program name contains a space program or command, combined with rule 2) and rule 3) to execute.

Exp:

& '. \show system Infomation.pls '

5) Special points in PowerShell

We know that at the cmd prompt, double quotes are used to implement commands that access spaces or commands under the path, whereas double quotes in PowerShell have special uses:

Represents a string.

Exp:

If we enter at the PS command prompt: "Hello" + "World" output:

Hello World

That is, double quotes in PS follow the C language specification.

6) The built-in cmdlets for entering PowerShell in any path can be executed without the need to add. \ or & special control symbols.

Exp:

Get-process

Entering the above command implements the Tasklist function in CMD.

3, 2 cmdlets

The commands built into PowerShell called Cmdlets;cmdlet implementations have the following characteristics:

1) Uniform form of command

2) Support Pipeline function

3) output easy-to-manage objects that support object-oriented concepts

3.3 Customizing the PowerShell prompt and command aliases

The advent of PowerShell makes up for the console shell feature of Windows's congenital weakness, drawing on many bash shells or other linux/unix shells in PowerShell

Experience; The alias of a custom command is one of them.

There is a built-in variable in PowerShell: $profile; This variable indicates the PowerShell user custom profile. You can enter $profile in PowerShell

To see the contents of this variable:

PS C:\Users\vol_20120330> $profile  C:\Users\vol_20120330\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.  ps1  PS C:\Users\vol_20120330>

Create a new user profile script file by using the following command:

new-item  -type file  force  $profile

The user's custom PowerShell environment profile is referenced by the $profile file and can be opened and edited by the following command:

notepad    $profile

Use the following command to get the configuration file: $profile information

Exp:

get-item  $profile

Get-item This command gets general information about the configuration file. You can also obtain $profile information by using the following command:

Get-childitem  $PROFILE

Let's use an example to modify the PowerShell command prompt, first open the User Configuration script file through the Notepade $profile, and then enter the following information:

Function  Prompt{        "PS [$env:COMPUTERNAME]>volcanol>" }

This will change the command prompt to the following style:

PS [vol_20120305]volcanol>"    

Note the name of my computer is: vol_20120305

3, 4 PowerShell Security Enforcement policy

By default, PowerShell does not allow script files to be executed, and the user profiles above are included, if the security execution policy for PowerShell is not modified, the user above

The configuration file cannot be executed. It is not illustrated here, and the reader can experiment on his own.

Here's a quick introduction to how to modify the security execution policy for PowerShell.

1) Open the PowerShell prompt window as an administrator

2) Enter the following command:

set-executionpolicy   remotesigned

3) then re-start the PowerShell as a management member, and then you can see that the PS prompt is programmed in a custom form.

Or you can not quit PS, but do $profile User Configuration script once.

3, 5 custom command aliases

By customizing the command alias in the User Configuration script file, you can improve the editing efficiency of the script because the PS command is much longer than the cmd command, for example

The CD command is now replaced with the Set-location command, and the dir command is replaced with the Get-childitem command.

Use the: Set-alias command to set the command alias.

set-alias   newnew-objector

EXP: Sets the alias of the IE browser launch command.

set-alias   iexplorer  ‘c:\program files\internet explorer\iexplorer.exe‘

This allows the use of the Iexplorer command in PowerShell to start IE browser. This, of course, requires restarting PowerShell or performing a user profile script once.

3, 6 Find command

In the use of CMD, we have such experience, sometimes do not know what command to achieve the required functions, then we can use the help command to roughly search;

And see if there's a command we need. This process is also supported in PowerShell and we can search for commands; this is done by Get-command.

1) Get all the commands you can use, enter the following command

get-command

2) Gets the help information for the specified command

get-command     command_name

Example: Get-command get-process

3) search with wildcard characters

PowerShell supports wildcard search, and the perfect support for this feature is perfectly comparable to regular expressions under Linux.

get-command     *char*

When searching only for *, it is equivalent to: Get-command

get-command   *

For example, the command with TXT in the search command: Get-command *txt*

5) Search with parameters

You can use the Get-command search in PowerShell with option parameters,-verb and-noun, where the-verb option is used to search for commands with the specified verb, and-noun

The option is used to search for commands with a specified noun. The command format is as follows:

get-command   -verb   verb_nameget-command   -noun   noun_name

For example, search for commands that drive Word get: Get-command-verb get

Search for commands with a noun service: Get-command-noun service

3.7 cmdlets--Consistent Command interface pattern

PowerShell uses a command interface pattern called cmdlets, and all commands follow this command pattern:

动词-名词

such as: Get-command command, get is a verb, and command is a noun

get-process command, get is a verb, and process is a noun

Get-eventlog command, get is a verb, and eventlog is a noun.

The verb part of the command in cmdlets is taken from a set of verbs, while the noun part of the cmdlet command describes the object to which the cmdlet command operates.

3.8 Getting Help information

There are three ways to get help in cmd: a) Take advantage

b) use/? command options, such as CD/?

c) View System help Group information

There are four ways to do this in PowerShell:

A) using the Get-command command

b) using the GET-HELP command

c) Use-? Command options

d) View System Help information

Using the Get-command command and using the GET-HELP command to get command help information is different; Get-command directly from cmdlets, functions, variables

Scripts or aliases, while the GET-HELP command obtains information from the System Help topic file, usually the get-help command gets more help than Get-command

Command details.

1) Use the Get-command command to obtain help information:

EXP: Get get-help Help information with Get-command

get-command    get-help

If you need to get more detailed commands with the Get-command command, use the pipe and format-list commands, as follows:

get-command    command_name  | format-list

2) Use the GET-HELP command to obtain help information:

EXP: Using Get-help to get its own Help information

get-help   get-help

Use the Get-help command to get help information you can specify command options to get different levels of detail for the Help group information:

a)-detailed option; Gets the details of the help information for a particular command; For example: get-help-detailed get-process

b)-full option; Get all the help information for a specific command; For example: Get-help-full set-location

c)-examples option; Gets instance help information for a particular command; For example: Get-help-examples Get-childitem

The above is all the contents of this time, to be continued.

Powershell_ 0 Basic Self-study course _1_ first Knowledge PowerShell

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.