# Alias AC = add-contentasnp = add-pssnapinclc = clear-contentcli = clear-itemclp = clear-itempropertyclv = clear-variablecpi = copy-itemcpp = copy-itempropertycvpa = convert-pathdiff = compare-objectepal = export-aliasepcsv = export-csvfc = format-customfl = format-listforeach = foreach-object % = foreach-objectft = format-tablefw = format-widegal = Get-aliasgc = Get-contentgci = Get-childitemgcm = Get- Commandgdr = Get-psdriveghy = Get-historygi = Get-itemgl = Get-locationgm = Get-membergp = Get-itempropertygps = Get-processgroup = group-objectgsv = Get-servicegsnp = Get-historygi- authorization = Get-uniquegv = Get-variablegwmi = Get-wmiobjectiex = invoke-expressionihy = invoke-historyii = invoke-itemipal = import-aliasipcsv = import-csvmi = move-itemmp = move- itempropertynal = new-aliasndr = new-psdriveni = New-itemnv = new-variableoh = out-hostrdr = remove-psdriveri = remove-itemrni = rename-itemrnp = rename-itempropertyrp = remove-itempropertyrsnp = remove-pssnapinrv = remove-variablervpa = resolve-pathsal = set-aliassasv = start-servicesc = set-contentselect = select-objectsi = set-itemsl = set-locationsleep = start-sleepsort = sort-objectsp = set-itempropertyspps = stop-processspsv = stop-Servic ESV = set-variabletee = tee-objectwhere = where-object? = Where-objectwrite = write-outputcat = Get-contentcd = set-locationclear = clear-hostcp = copy-itemh = Get-historyhistory = Get-historykill = stop-processlp = out-printerls = Get-childitemmount = new-psdrivemv = move-itempopd = pop-locationps = Get-processpushd = Push-locationpwd = Get-locationr = invoke-historyrm = remove-itemrmdir = remove-itemecho = write-outputcls = clear-hostchdir = set-loca Tioncopy = copy-itemdel = remove-itemdir = Get-childitemerase = remove-itemmove = move-itemrd = remove-itemren = rename-itemset = set-variabletype = Get-content # psdrivealiascertenvfunctionhkcuhklmvariable # obtain help get * help * processhelp dirhelp Dir-fullhelp Dir-detailedhelp Dir-exampledir -? # Escape Sequence '0 // null value 'a // beep 'B // return the lattice 'f // newline 'n // New Line 'r // press ENTER' t // tab 'v // vertical quotation marks ''//" '"# numerical constant 1kb // 1024 1 MB 1 GB 1e3 // 1000 0 xFFFF // 65535 # edit the script, we recommend that you use the latest version of primalscript, very powerful # Set the Script Security Policy set-executionpolicy restricted # default set-executionpolicy allsigned # deploy set-executionpolicy remotesigned # develop set-executionpolicy unrestricted # Not recommended # The execution script must have a path. /myscript. PS1 # Get the credential object based on the user name and password $ Cert = Get-credential # sign the script $ Cert = Get-pfxcert Ificate c: \ test \ mysign. pfxset-authenticodesignature myscript. PS1-Cert $ Cert # operating system gwmi win32_operatingsystem # automatic variable $ ARGs # parameters passed into the function $ _ # objects passed through the pipeline $ input # collection of objects passed through the pipeline $ # Last mark of the previous command line $? # Boolean status of the previous command $ ^ # first mark of the previous command line $ matches # hash table of matched items found using the-match operator $ error [0] # previous error $ home # Your home directory $ host # reference the application of the host powershell LanguageProgram $ Lastexitcode # exit of the previous program or script Code $ Pshome # installation location of Windows powershell $ profile # standard configuration file (may not exist) $ stacktrace # previous exception captured by Windows powershell # type null type [void] value type [byte] typeof (byte) [decimal] typeof (decimal) [double] typeof (double) [float] typeof (float) [int] typeof (INT) [long] typeof (long) [single] typeof (float) character type [char] typeof (char) [String] typeof (string) Boolean Type [bool] typeof (bool) set type [array] typeof (system. array) typeof (system. object []) [hashtable] typeof (system. collections. hashtable) other [psobject] typeof (system. management. automation. psobject) [Ref] typeof (system. management. automation. psreference) [RegEx] typeof (system. text. regularexpressions. regEx) [scriptblock] typeof (system. management. automation. scriptblock) [Switch] typeof (system. management. automation. switchparameter) [type] typeof (system. type) [WMI] typeof (system. management. managementobject) [wmiclass] typeof (system. management. managementclass) [wmisearcher] typeof (system. management. managementobjectsearcher) [XML] typeof (system. XML. xmldocument) Example: # [void] [void] $ var # block $ var output # [XML] $ Var = [XML]"
One
two
3
"$ Var. TOP $ var. top. A $ var. top. A = "13" # custom function writeln ([String] $ Str) {echo $ STR} function writeln ([String] $ Str) {begin {echo "begin"} process {echo $ STR} end {echo "end"} function writeln {param ([String] $ STR = $ (throw "missing parameter" )); echo $ STR }$ {function: writeln }={ param ([String] $ STR =$ (throw "missing parameter ")); echo $ STR} # Read and Write text files $ {C: \ test.txt} = "Hello 'r'n'" $ {C: \ test.txt} + = "-----------------" $ Line1 =$ {C: \ test.txt} [0] # $ null $ Var = $ null # Delete $ vardir> $ null = dir # invoke $ method = "toupper" "ABC ". $ method. invoke () # Boolean value $ true $ false # Where, select, and other usage cd c: \ dir | where {$ _. name-EQ "Windows"} | select length, namedir |? {$ _. Name-EQ "Windows"} # list all attributes and methods of the string object "str" "str" | GM # force type variable [Boolean] $ condition = 0 [String] $ Str = "hello" # array $ array = 1, 2, 3, 4, 5, 6, 7, 8 $ array = @ (1, 2, 3, 4, 5, 6, 7, 8) $ array [-1] # The last element $ array [0 .. 4] $ array [-1 .. -8] # Reverse Order # hash table $ hash = @ {"name" = "icebird"; "job" = "engineer"} # How to obtain the number of lines of text (Type C: \ test.txt | measure-object ). count # Read a row from the console and enter $ Var = read-host # obtain the environment variable $ Path = $ ENV: path # Read the Registry $ A = (GP "HKLM: \ Software \ microsof T \ Windows \ CurrentVersion "). productid # comparison and computation-like "file.doc"-like "file. * "-notlike-contains1, 2,3-contains 1-notcontains ------------------------------------- eq = (case-insensitive)-ieq = (case-insensitive)-CEQ = (case-insensitive)-ne! =-GT>-lt <-ge> =-Le <= the preceding operators can also be used for Array Operations: 1, 2, 5, 3, 2-lt 3 ------------------------------- and-or-not! It is equivalent to the-not-XOR % modulo operation * which can be used to repeat strings: "-" * 80 # bit operation-band-Bor-bnot-bxor # Special Operation $ A = "hat" $ A-Replace "", "O" $ A-is [String] $ A = 1-as [String] $ B = @ (1 .. 5) "{0: d}"-F (get-date) "{0: yyyy-mm-dd}"-F (get-date) # format $ A = 123456789.456789 $. tostring ("F4") "{0: F4}"-F $ A "{0,-20: F4} {1}"-F $ A, 0 "{0, 20: f4} "-F $ A" {0: x} "-F 100000" {0: x} "-F 100000 # Regular Expression $ RegEx = [RegEx]" he "$ STR =" Hello, hello "$ ismatch = $ str-match $ RegEx $ ismatc H = $ RegEx. ismatch ($ Str) $ matches = $ RegEx. matches ($ Str) # Double quotation marks and single quotation marks $ A = 1; "$ A" will output 1 '$ a' and $ .. {$ Var = 1} # Think of it as include & {$ Var = 1} # Think of it as call & "dir" # meaning that the function name and so on can be passed in as a parameter # foreachforeach ($ file in Dir) {$ file. name} dir | % {$ _. name} # forfor ($ I = 1; $ I-lt 5; $ I ++) {echo $ I} # while $ I = 0 while ($ I-lt 4) {$ I ++; $ I} # Do... while $ I = 10do {$ I --; $ I} while ($ I-lt 5) # Do... until $ I = 10do {$ I --; $ I} until ($ I-lt 5) # If... else [if] $ OBJ = "hello" if ($ obj-is [String]) {"isstring"} if ($ obj-is [String]) {"isstring"} else {"isnotstring"} if ($ obj-is [String]) {"isstring"} elseif ($ obj-is [int]) {"isinteger"} # switchswitch (1, 2, 3) {1 {"A"} 2 {"B"} 3 {"C"} default {"? "}} Switch (1) {" A "{" China "}" B "{" Japan "}" C "{" C "} default {"??? "}}# Switch-RegEx $ Var =" abcdefg "Switch-RegEx ($ var) {"^ \ W + $" {echo $ _ "is a word"} "^ \ D + $" {echo $ _ "is a number"} "^ \ s + $ "{echo $ _" is a space "} default {echo "? "}}# Switch-casesensitive # Switch-Wildcard # Switch-extract? How to Use # Switch-file? How to Use # throw an error & capture an exception throw "error" Raised "exception" trap {write-host "error:" $ _. exception. message # $ _. targetobject # $ _. categoryinfo # $ _. fullyqualifiederrorid # $ _. errordetails # $ _. invocationinfo continue # break # Return} # output format-listformat-tableformat-wideformat-customdir | format-table-groupby modedir | sort name-descdir | sort name-Desc | select name, length, mode | export-CSV c: \ dir.csv dir | sort name-Desc | select name, length, mode | export-clixml c: \ dir.csv dir | convertid-html # usage. net object $ WebClient = new-Object System. net. webClient $ WebClient. encoding = [system. text. encoding]: utf8 $ url = "http://www.cnblogs.com/rss" $ DATA = [String] $ WebClient. downloadstring ($ URL) # Use the COM Object $ spvoice = new-object-com "SAPI. spvoice "$ spvoice. speak ("Hello, I am icebird. ")