共用方式為


about_Reserved_Words

簡短描述

列出無法做為標識碼的保留字,因為它們在PowerShell中具有特殊意義。

詳細描述

PowerShell 中有某些字詞具有特殊意義。 當這些字沒有引號出現時,PowerShell 會嘗試套用其特殊意義,而不是將它們視為字元字串。 若要在命令或腳本中使用這些單字做為參數自變數,而不叫用其特殊意義,請用引號括住保留字。

以下是 PowerShell 中的保留字:

assembly         exit            process
base             filter          public
begin            finally         return
break            for             sequence
catch            foreach         static
class            from (*)        switch
command          function        throw
configuration    hidden          trap
continue         if              try
data             in              type
define (*)       inlinescript    until
do               interface       using
dynamicparam     module          var (*)
else             namespace       while
elseif           parallel        workflow
end              param
enum             private

(*) These keywords are reserved for future use.

數個語言關鍵詞,包括 foreachifforwhile,都有自己的說明文章。 若要檢視它們,請輸入 Get-Help about_ 並新增 關鍵詞。 例如,若要取得 語句的相關信息 foreach ,請輸入:

Get-Help about_ForEach

如需語句或return語句語法的相關信息filter,請輸入:

Get-Help about_Functions

如需其他保留字的相關信息,請輸入:

Get-Help <Reserved_Word>

注意

並不是每個保留字都有自己的說明文章。 如果未 Get-Help 傳回發行項,您可以使用下列命令來搜尋談論保留字的文章:

Get-Help <Reserved_Word> -Category:HelpFile

另請參閱