8.6 switch 陳述式語法:Syntax 複製 switch-statement: switch new-lines~opt~ switch-parameters~opt~ switch-condition switch-body switch-parameters: switch-parameter switch-parameters switch-parameter switch-parameter: -regex -wildcard -exact -casesensitive -parallel switch-condition: ( new-lines~opt~ ...
If no parameters are used,switchbehaves the same as using theExactparameter. It performs a case-insensitive match for the value. If the value is a collection, each element is evaluated in the order in which it appears. Theswitchstatement must include at least one condition statement. ...
filter [<scope:>]<name> {<statement list>} 下列篩選會從管線擷取記錄專案,然後顯示整個專案或只顯示項目的訊息部分: PowerShell filterGet-ErrorLog([switch]$Message) {if($Message) {Out-Host-InputObject$_.Message }else{$_} } 其用法如下: ...
針對Select-String,請使用 CaseSensitive 參數。 對於使用正則表達式的運算符,請使用區分大小寫的版本: -cmatch、 -creplace或-csplit switch針對語句,請使用 -casesensitive 選項字元常值正則表達式可以是常值字元或字串。 表達式會使引擎完全符合指定的文字。PowerShell 複製 ...
Windows PowerShell Tip: Using the Switch Statement Windows PowerShell Tip: Working With Custom Objects Windows PowerShell Tip: Working With SIDs Windows PowerShell Tip: Working With Security Descriptors Working with Hash Tables Accessing WMI from Windows PowerShell Hip, Hip, Array—Retrieving Multi-...
Windows PowerShell Tip: Using the Switch Statement Windows PowerShell Tip: Working With Custom Objects Windows PowerShell Tip: Working With SIDs Windows PowerShell Tip: Working With Security Descriptors Working with Hash Tables Accessing WMI from Windows PowerShell Hip, Hip, Array—Retrieving Multi-...
Fine, but how do we do that in a script that will work for any INI file? Easy:“switch -regex” (get-help switch). To figure out if a line is a comment, section, or key, we will use aregular expressionwith theswitchstatement. ...
filter [<scope:>]<name> {<statement list>} The following filter takes log entries from the pipeline and then displays either the whole entry or only the message portion of the entry: PowerShell Copy filter Get-ErrorLog ([switch]$Message) { if ($Message) { Out-Host -InputObject $_...
PowerShell’sswitchstatement lets you easily test its input against a large number of comparisons. Theswitchstatement supports several options that allow you to configure how PowerShell compares the input against the conditions—such as with a wildcard, regular expression, or even an arbitrary script...
Theswitchstatement in PowerShell has been given special functionality for parsing text. It has two flags that are useful for parsing text and files with text in them.-regexand-file. When specifying-regex, the match clauses that are strings are treated as regular expressions. The switch statemen...