8. PowerShell-Basic overview, variables, character and string manipulation, operator operations

Source: Internet
Author: User

    • PowerShell Basic outline of the script

    1. constants, use of variables

    2. Operations on various strings

    3. Operations on operators

    4. arrays, hash tables: creating, modifying merged arrays and hash tables

    5. Conditional judgment:If, switch statement

    6. Logical judgment: Using operators to judge

    7. loop control:while, Do...while, do ... until, For,foreach statements

    8. Modular: organize and adjust code; Use the exact data type to invoke other script functions

    9. WMI object:

      The WMI namespace concept,WMI provides the functionality to view and use the WMI namespace.

      WMI class:get-wmiobject; Enquiry Wmi

    10. ADSI Object

      the concept of Active Directory objects;

      the functionality that ADSI provides;

      Active Directory namespace;

      Create and modify ActiveDirectory Object

Reference: http://marui.blog.51cto.com/1034148/291383

    • PowerShell the variable

  1. Assignment of variables:

    $STR = "123"

    or set-variable-name str–value "123"

  2. when declaring variables, avoid some "system reserved words", such as:

    Break | Continue | do | else | ElseIf |filter | foreach | function | If | In | return | Switch | Until | where | While

  3. Output variables

    Write-output $str

    or enter $STR directly

    • Characters and strings for PowerShell

      1. The following are common data type descriptions for PowerShell:

Hashtable : Hash Table

BOOL : true , false

XML : XML Object

Array : Array

decimal : decimal number, 128bit

byte : unsigned characters, 8bit

Char : Unicode encoded characters, 16bit

string : Unicode encoded string

Single : Single Precision 32bit floating point

Double : Double Precision 64bit floating point

Long : Signed, 64bit

int: There are symbols, 32bit


$strA = "Hello" <enter>

$strB = "world!" <enter>

$strC = $strA + $strB <enter>

$strC <enter> Results: "Hello world!"

String substitution:

$strA = "hi! world! "<enter>

$strB = $strA-replace "hi!", "Hello" <enter>

$strB <enter> Results: "hi!,world!"

String reference:

$strA = "ABC" <enter>

"This is $strA." <enter> Results: "Thisis ABC"

' This is $strA. ' <enter> Results: "This is $strA"

    • PowerShell operator operation (+,-, *,/,%,=,++,-- )

5 + <enter>

$x =200+1 <enter>

$x <enter>

[int] $y = (7 + * 2)/10<enter>

$y <enter> Results: 3


Reference: http://marui.blog.51cto.com/1034148/291383


This article comes from the "Ricky's blog" blog, please be sure to keep this source http://57388.blog.51cto.com/47388/1639140

8. PowerShell-Basic overview, variables, character and string manipulation, operator operations

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.