Windows powershell Basics

Source: Internet
Author: User

Basic powershell knowledge point

1. The file name of the powershell script file is extended with. PS1 (note that it is the number 1)

2. powershell execution Policy
The default value is restricted. You can use the following command to obtain the current execution policy:
Get-executionpolicy
Optional execution policies are as follows:
Restricted-the script cannot be run.
Remotesigned-locally created scripts can run, but scripts downloaded from the Internet cannot run (unless they have a digital signature signed by a trusted publisher)
Allsigned-the script can only run if it is signed by a trusted publisher.
Unrestricted-script execution is unrestricted, regardless of the source or signature
You can use the following cmdlet command to reset the execution policy:
Set-executionpolicy <Policy Name>

3. Run the script
Enter the full path of the script, such as D: \ scripts \ script. PSI.
If the script file is located in the system directory, you can type. \ script. PSI to run it.
Note. \ cannot save

4. Pipelines
Get-process | sort-Object ID
Obtain the process list and sort by process ID

5. Variables
$ A = Get-Process
$ B = (get-process | sort-Object ID)

6. @ symbol
You can use the @ symbol to convert the list content to an array, for example:
$ Procs =@{ name = "Explorer", "taskmgr "}
Get-process @ procs
Add @ in the second line to ensure that procs is processed as an array

7. Split
"This is a test"-split ""

8. Join
"Hello", "world"-join ","

9. breakpoint
Insert a breakpoint Based on the row number:
New-psbreakpint-script D: \ scripts \ script. PS1-line 10
Insert a breakpoint in line 2 of the script
You can also bind a breakpoint to a variable:
New-psbreakpoint-script D: \ scripts \ script. PS1-variables
Other Commands include:
Get-psbreakpoint
Enable-psbreakpoint
Disable-psbreakpoint
Remove-psbreakpoint

10. Single-step debugging
Step-
Step-out

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.