Explore PowerShell (v) PowerShell basic knowledge _powershell

Source: Internet
Author: User

In PowerShell, we can easily interact with data and objects, and in order to simplify our access to external data, PowerShell allows us to manipulate data, objects, and so on, as we do with drives and files.

Use this command to view our existing providers:

Get-psprovider

In fact, each provider is a dynamic link library (. dll), which can also be called a "snap-in" in PowerShell, with detailed code in the snap-in to implement our various operations. PowerShell even allows us to write our own provider:http://msdn.microsoft.com/en-us/library/cc136763 (vs.85). aspx

We have a lot of ways to manipulate data, such as:

Cmdlet Function CMD command Alias
Get-location Current directory Pwd Gl
Set-location Change Operation Directory Cd,chdir Sl
New-item Create a new file or folder No Ni
Rename-item Renaming Rn Rni
Copy-item Copy Copy Cpi
Move-item Move Move Mi
Remove-item Delete Del Ri
Set-item Set content No Si
Clear-item Delete Content No Cli
Mkdir Create a new Folder Md No
Set-content Set content No Sc
Get-content Get content Type Gc

Psdriver

You can get the current drive list through the Psdriver in PowerShell, and basically all provider have a unique psdriver, but the file system and the registry are exceptions, and the following command allows you to view:

Get-psdriver

Note: the "Name" in the previous illustration does not show a colon (:), but we must add it when we use it, such as Alias:, C:, and so on.

Environment variables

The environment variable in PowerShell is similar to the "set" command in CMD, and you can use the following command to view environment variable settings on the current machine:

CD env:

Ls

We try to get the values of some environment variables.

LS OS

Show All properties:

LS OS | Format-list *

Try again. Create a new environment variable:

New-item-path. -Name new-value "New" <enter>



Next, let's take a look at the "Mode" shown in "Get-childitem".

First digit: D represents folder-Represents directory

Post four digits (A, R, H, s): A archive R Read only h hidden S system-indicates that bit is not set

By default, "Get-childitem" does not display hidden files. Therefore, we need to use the parameter "-force".

<enter>

So what about the new file creation? Let's try the following command:

New-item NewFile

The input file type, "file", "directory", is required, and we use "F" and "D".

Or, use parameters when you are new:

function in the PowerShell

PowerShell provides an engine for us to invoke various functions to implement the function. Let's take a look at our own functions:

CD function:

Ls

Next, look at the "clear-host" function with the cmdlet you've introduced:

Get-content Clear-host

Therefore, we can for convenience, as far as possible to create some blocks of code to achieve a specific function, the rest to do is just called. Is it convenient? In the following tutorial I will introduce myself to write functions to implement the function call.

Registration Form

In PowerShell we can manipulate the registry like an operation file. PowerShell allows us to operate on HKCU and HKLM.

Hkcu:hkey_current_user

Hklm:hkey_local_machine

Try the following command:

CD HKLM:

CD software

Ls

Certificate

CD cert:

Ls

Export Look at it ~

Ls-recurse | Export-csv "D:\Cert.csv"

Well, this section of the content to here ~ things are more miscellaneous, but also relatively trivial, but these will greatly deepen our understanding of PowerShell and understanding, to help us to better learning.

Also to the weekend, I wish you a happy weekend! Thanks for the attention of this blog ~ Thank you!

New-item Newfile-type F

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.