第 2 章 - 說明系統

有兩組 IT 專業人員獲得書面測試,而無法存取計算機,以使用 PowerShell 判斷其技能等級。 PowerShell 初學者被放在一個群組中,另一個小組和專家。 根據測試結果,這兩個群組之間的技能等級似乎沒有太大差異。 這兩個群組都得到了第二次測試,類似於第一個測試。 這一次,他們被授與使用PowerShell的計算機存取權,而該電腦無法存取因特網。 第二次測試的結果顯示,這兩組技能水準有很大的差異。 專家並不總是知道答案,但他們知道如何找出答案。

這兩個群組之間第一次和第二次測試結果的差異為何?

這兩項測試中觀察到的差異是因為專家不會記住如何在PowerShell中使用數千個命令。 他們瞭解如何在PowerShell中非常妥善地使用說明系統。 這可讓他們在需要時尋找必要的命令,以及如何在找到這些命令之後使用這些命令。

我聽過 PowerShell 的發明者 Jeffrey Snover 多次講述類似的故事。

掌握說明系統是使用PowerShell成功的關鍵。

發現性

PowerShell 中的已編譯命令稱為 Cmdlet。 Cmdlet 發音為 “command-let” (而不是 CMD-let)。 Cmdlet 名稱具有單一的 “Verb-Noun” 命令形式,讓它們更容易探索。 例如,用來判斷執行哪些進程的 Cmdlet, Get-Process 以及擷取服務清單的 Cmdlet,其狀態為 Get-Service。 PowerShell 中有其他類型的命令,例如本文稍後將涵蓋的別名和函式。 PowerShell 命令一詞是一般詞彙,通常用來參考 PowerShell 中任何類型的命令,不論其是否為 Cmdlet、函式或別名。

PowerShell 中的三個核心 Cmdlet

  • Get-Command
  • Get-Help
  • Get-Member (第3章涵蓋)

我經常被問及的一個問題是如何找出 PowerShell 中的命令為何? 和 Get-CommandGet-Help 都可以用來判斷命令。

Get-Help

Get-Help 是多重用途命令。 Get-Help 可協助您瞭解如何在找到命令之後使用命令。 Get-Help 也可以用來協助尋找命令,但相較於 Get-Command,則以不同且更間接的方式。

當 用來尋找命令時 Get-Help ,它會先根據提供的輸入搜尋命令名稱的通配符相符專案。 如果找不到相符專案,則會搜尋說明主題本身,如果找不到相符專案,則會傳回錯誤。 與流行信仰相反, Get-Help 可以用來尋找沒有幫助主題的命令。

您需要瞭解 PowerShell 中說明系統的第一件事,就是如何使用 Get-Help Cmdlet。 下列命令可用來顯示 的說明 Get-Help主題。

Get-Help -Name Get-Help
Do you want to run Update-Help?
The Update-Help cmdlet downloads the most current Help files for Windows PowerShell
modules, and installs them on your computer. For more information about the Update-Help
cmdlet, see http://go.microsoft.com/fwlink/?LinkId=210614.
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"):

從 PowerShell 第 3 版開始,PowerShell 說明不會隨附於操作系統。 第一次 Get-Help 針對命令執行時,會顯示先前的訊息。 如果使用函 help 式或 man 別名, Get-Help 而不是 Cmdlet,則不會收到此提示。

Y 回答是會執行 Update-Help Cmdlet,預設需要因特網存取。 Y 可以在大寫或小寫中指定。

下載說明並完成更新之後,就會針對指定的命令傳回說明主題:

Get-Help -Name Get-Help

請花點時間在電腦上執行該範例、檢閱輸出,並記下資訊分組方式:

  • NAME
  • 簡介
  • 語法
  • 描述
  • 相關連結
  • REMARKS

如您所見,說明主題可以包含大量的資訊,甚至不是整個幫助主題。

雖然不是 PowerShell 特有的,但參數是提供命令輸入的方法。 Get-Help 有許多可以指定的參數,以便傳回整個說明主題或它的子集。

上一組結果所顯示說明主題的語法區段會列出 的所有參數 Get-Help。 一眼就會出現相同的參數,會列出六次不同的參數。 語法區段中每個不同的區塊都是參數集。 這表示 Get-Help Cmdlet 有六個不同的參數集。 如果您仔細查看,您會發現每個參數集至少有一個參數不同。

參數集互斥。 一旦只存在於其中一個參數集中的唯一參數使用后,就只能使用包含在該參數集中的參數。 例如, 無法同時指定 FullDetailed 參數,因為它們位於不同的參數集中。

下列每個參數都位於不同的參數集中:

  • 完整
  • 詳細
  • 範例
  • 線上存取
  • 參數
  • ShowWindow

語法區段中的所有神秘語法,例如方括弧和角括弧,都表示本書附錄 A 將涵蓋某些內容。 雖然很重要,但對於不熟悉PowerShell的人來說,學習神秘語法通常很難保留,而且可能不每天使用它。

如需進一步瞭解神秘語法的詳細資訊,請參閱 附錄 A

對於初學者來說,除了純語言之外,還有一種更容易找出相同資訊的方法。

指定的 Full 參數Get-Help時,會傳回整個說明主題。

Get-Help -Name Get-Help -Full

請花點時間在電腦上執行該範例、檢閱輸出,並記下資訊分組方式:

  • NAME
  • 簡介
  • 語法
  • 描述
  • PARAMETERS
  • 輸入
  • 輸出
  • 注意
  • 例子
  • 相關連結

請注意,使用 Full 參數傳回數個額外的區段,其中一個是 PARAMETERS 區段,提供比神秘的 SYNTAX 區段更多的資訊。

Full 參數是 switch 參數。 不需要值的參數稱為 switch 參數。 指定 switch 參數時,其值為 true,而當它不是時,其值為 false。

如果您已在PowerShell控制台中完成本章的工作,您注意到上一個命令會顯示在螢幕上飛來的完整幫助主題 Get-Help ,而不需要讓您有機會閱讀。 還有更好的處理方法。

Help 是一個函 Get-Help 式,會管線傳送至名為 more的函式,這是 Windows 中可執行檔的 more.com 包裝函式。 在 PowerShell 控制台中, help 一次提供一頁說明。 在 ISE 中,其運作方式與 Get-Help相同。 我的建議是使用 函 help 式,而不是 Get-Help Cmdlet,因為它提供較佳的體驗,而且類型比較少。

不過,不一定是一件好事。 如果您要將命令儲存為腳本或與其他人共用,請務必使用完整的 Cmdlet 和參數名稱。 完整名稱是自我記載,因此更容易瞭解。 想想下一個必須閱讀並瞭解命令的人員。 可能是你 你的同事和未來的自我將感謝你。

請嘗試在 Windows 10 實驗室環境電腦上的 PowerShell 控制台中執行下列命令。

Get-Help -Name Get-Help -Full
help -Name Get-Help -Full
help Get-Help -Full

當您在 Windows 10 實驗室環境電腦上執行命令時,您是否注意到先前所列命令的輸出有任何差異?

除了最後兩個選項之外,沒有任何差異會一次傳回一頁的結果。 使用 函式時Help,空格鍵可用來顯示下一頁的內容,而 Ctrl+C 會取消在 PowerShell 控制台中執行的命令。

第一個範例使用 Get-Help Cmdlet,第二個會使用 HelpHelp 函式,而第三個則使用 函式時省略 Name 參數。 Name 是位置參數,而且該範例中正以位置方式使用。 這表示可以指定值而不指定參數名稱,只要值本身指定在正確的位置即可。 如何知道在 中指定值的位置? 閱讀說明,如下列範例所示。

help Get-Help -Parameter Name
-Name <String>
    Gets help about the specified command or concept. Enter the name of a cmdlet, function,
    provider, script, or workflow, such as Get-Member, a conceptual article name, such as
    about_Objects, or an alias, such as ls. Wildcard characters are permitted in cmdlet and
    provider names, but you can't use wildcard characters to find the names of function help and
    script help articles.

    To get help for a script that isn't located in a path that's listed in the $env:Path
    environment variable, type the script's path and file name.

    If you enter the exact name of a help article, Get-Help displays the article contents.

    If you enter a word or word pattern that appears in several help article titles, Get-Help
    displays a list of the matching titles.

    If you enter a word that doesn't match any help article titles, Get-Help displays a list of
    articles that include that word in their contents.

    The names of conceptual articles, such as about_Objects, must be entered in English, even in
    non-English versions of PowerShell.

    Required?                    false
    Position?                    0
    Default value                None
    Accept pipeline input?       True (ByPropertyName)
    Accept wildcard characters?  true

請注意,在上一個範例中,Parameter 參數與 Help 函式搭配使用,只傳回 Name 參數幫助主題的資訊。 這比嘗試手動篩選有時看起來像一百頁說明主題更簡潔。

根據這些結果,您可以看到 Name 參數為位置,且必須在位置零(第一個位置)中指定。 中指定參數的順序在指定參數名稱時並不重要。

另一個重要資訊是 Name 參數預期其值的數據類型為單一字串,以表示 <String>。 如果它接受多個字串,資料類型會列為 <String[]>

有時候您只是不想顯示命令的整個說明主題。 除了 Full 之外,還有一些其他參數可以使用 或 Help來指定Get-Help。 請嘗試在 Windows 10 實驗室環境電腦上執行下列命令:

Get-Help -Name Get-Command -Full
Get-Help -Name Get-Command -Detailed
Get-Help -Name Get-Command -Examples
Get-Help -Name Get-Command -Online
Get-Help -Name Get-Command -Parameter Noun
Get-Help -Name Get-Command -ShowWindow

我通常會搭配 FullOnline 參數使用help <command name>。 如果我只對範例感興趣,我會使用 Examples 參數,如果我只對特定參數感興趣,我會使用 Parameter 參數。 ShowWindow 參數會在個別的可搜尋視窗中開啟說明主題,如果您有多個監視器,則可以放在不同的監視器上。 我已避免 ShowWindow 參數,因為有一個已知的 Bug,它不會顯示整個說明主題。

如果您想要在個別視窗中取得協助,我的建議是使用 Online 參數或使用 Full 參數,並將結果傳送至 Out-GridView,如下列範例所示。

help Get-Command -Full | Out-GridView

Out-GridView Cmdlet 和 Cmdlet 的 Get-Help ShowWindow 參數都需要具有 GUI 的作業系統(圖形使用者介面)。 如果您嘗試在使用伺服器核心 (no-GUI) 安裝選項安裝的 Windows Server 上使用其中一個,它們將會產生錯誤訊息。

若要使用 Get-Help 來尋找命令,請使用星號 (*) 通配符搭配 Name 參數。 指定您要搜尋命令的字詞做為 Name 參數的值,如下列範例所示。

help *process*
Name                              Category  Module                    Synopsis
----                              --------  ------                    --------
Enter-PSHostProcess               Cmdlet    Microsoft.PowerShell.Core Connects to and ...
Exit-PSHostProcess                Cmdlet    Microsoft.PowerShell.Core Closes an intera...
Get-PSHostProcessInfo             Cmdlet    Microsoft.PowerShell.Core
Debug-Process                     Cmdlet    Microsoft.PowerShell.M... Debugs one or mo...
Get-Process                       Cmdlet    Microsoft.PowerShell.M... Gets the process...
Start-Process                     Cmdlet    Microsoft.PowerShell.M... Starts one or mo...
Stop-Process                      Cmdlet    Microsoft.PowerShell.M... Stops one or mor...
Wait-Process                      Cmdlet    Microsoft.PowerShell.M... Waits for the pr...
Get-AppvVirtualProcess            Function  AppvClient                ...
Start-AppvVirtualProcess          Function  AppvClient                ...

在上一個範例中 * ,不需要通配符,並省略它們會產生相同的結果。 Get-Help 會自動在幕後新增通配符。

help process

上一個命令會產生與在每個 * 進程結尾指定通配符相同的結果。

我寧願新增它們,因為這是總是一致運作的選項。 否則,某些案例中不需要它們,而不是其他案例。 一旦您在值中間新增通配符,這些通配符就不會再自動在幕後新增至您指定的值。

help pr*cess

除非 * 通配符新增至開頭、結尾或 開頭和結尾 pr*cess,否則該命令不會傳回任何結果。

如果您指定的值是以破折號開頭,則會產生錯誤,因為PowerShell會將它解譯為參數名稱,而且 Cmdlet 沒有這類參數名稱 Get-Help 存在。

help -process

如果您嘗試尋找的命令是結尾為 -process的命令,則只需要將 * 通配符新增至值的開頭。

help *-process

使用 搜尋 PowerShell 命令 Get-Help時,您想要稍微模糊一點,而不是針對您要搜尋的內容過於明確。

process搜尋先前只找到包含在命令名稱中的命令process,並只傳回這些結果。 當 用來搜尋 processesGet-Help,它找不到命令名稱的任何相符專案,因此它會在您的系統上的PowerShell中執行每個說明主題的搜尋,並傳回它找到的任何相符專案。 這會導致它傳回大量的結果。

Get-Help processes
Name                              Category  Module                    Synopsis
----                              --------  ------                    --------
Disconnect-PSSession              Cmdlet    Microsoft.PowerShell.Core Disconnects from...
Enter-PSHostProcess               Cmdlet    Microsoft.PowerShell.Core Connects to and ...
ForEach-Object                    Cmdlet    Microsoft.PowerShell.Core Performs an oper...
Get-PSSessionConfiguration        Cmdlet    Microsoft.PowerShell.Core Gets the registe...
New-PSTransportOption             Cmdlet    Microsoft.PowerShell.Core Creates an objec...
Out-Host                          Cmdlet    Microsoft.PowerShell.Core Sends output to ...
Where-Object                      Cmdlet    Microsoft.PowerShell.Core Selects objects ...
Clear-Variable                    Cmdlet    Microsoft.PowerShell.U... Deletes the valu...
Compare-Object                    Cmdlet    Microsoft.PowerShell.U... Compares two set...
Convert-String                    Cmdlet    Microsoft.PowerShell.U... Formats a string...
ConvertFrom-Csv                   Cmdlet    Microsoft.PowerShell.U... Converts object ...
ConvertTo-Html                    Cmdlet    Microsoft.PowerShell.U... Converts Microso...
ConvertTo-Xml                     Cmdlet    Microsoft.PowerShell.U... Creates an XML-b...
Debug-Runspace                    Cmdlet    Microsoft.PowerShell.U... Starts an intera...
Export-Csv                        Cmdlet    Microsoft.PowerShell.U... Converts objects...
Export-FormatData                 Cmdlet    Microsoft.PowerShell.U... Saves formatting...
Format-List                       Cmdlet    Microsoft.PowerShell.U... Formats the outp...
Format-Table                      Cmdlet    Microsoft.PowerShell.U... Formats the outp...
Get-Random                        Cmdlet    Microsoft.PowerShell.U... Gets a random nu...
Get-Unique                        Cmdlet    Microsoft.PowerShell.U... Returns unique i...
Group-Object                      Cmdlet    Microsoft.PowerShell.U... Groups objects t...
Import-Clixml                     Cmdlet    Microsoft.PowerShell.U... Imports a CLIXML...
Import-Csv                        Cmdlet    Microsoft.PowerShell.U... Creates table-li...
Measure-Object                    Cmdlet    Microsoft.PowerShell.U... Calculates the n...
Out-File                          Cmdlet    Microsoft.PowerShell.U... Sends output to ...
Out-GridView                      Cmdlet    Microsoft.PowerShell.U... Sends output to ...
Select-Object                     Cmdlet    Microsoft.PowerShell.U... Selects objects ...
Set-Variable                      Cmdlet    Microsoft.PowerShell.U... Sets the value o...
Sort-Object                       Cmdlet    Microsoft.PowerShell.U... Sorts objects by...
Tee-Object                        Cmdlet    Microsoft.PowerShell.U... Saves command ou...
Trace-Command                     Cmdlet    Microsoft.PowerShell.U... Configures and s...
Write-Output                      Cmdlet    Microsoft.PowerShell.U... Sends the specif...
Debug-Process                     Cmdlet    Microsoft.PowerShell.M... Debugs one or mo...
Get-Process                       Cmdlet    Microsoft.PowerShell.M... Gets the process...
Get-WmiObject                     Cmdlet    Microsoft.PowerShell.M... Gets instances o...
Start-Process                     Cmdlet    Microsoft.PowerShell.M... Starts one or mo...
Stop-Process                      Cmdlet    Microsoft.PowerShell.M... Stops one or mor...
Wait-Process                      Cmdlet    Microsoft.PowerShell.M... Waits for the pr...
Get-Counter                       Cmdlet    Microsoft.PowerShell.D... Gets performance...
Invoke-WSManAction                Cmdlet    Microsoft.WSMan.Manage... Invokes an actio...
Remove-WSManInstance              Cmdlet    Microsoft.WSMan.Manage... Deletes a manage...
Get-WSManInstance                 Cmdlet    Microsoft.WSMan.Manage... Displays managem...
New-WSManInstance                 Cmdlet    Microsoft.WSMan.Manage... Creates a new in...
Set-WSManInstance                 Cmdlet    Microsoft.WSMan.Manage... Modifies the man...
about_Arithmetic_Operators        HelpFile                            Describes the op...
about_Arrays                      HelpFile                            Describes arrays...
about_Debuggers                   HelpFile                            Describes the Wi...
about_Execution_Policies          HelpFile                            Describes the Wi...
about_ForEach-Parallel            HelpFile                            Describes the Fo...
about_Foreach                     HelpFile                            Describes a lang...
about_Functions                   HelpFile                            Describes how to...
about_Language_Keywords           HelpFile                            Describes the ke...
about_Methods                     HelpFile                            Describes how to...
about_Objects                     HelpFile                            Provides essenti...
about_Parallel                    HelpFile                            Describes the Pa...
about_Pipelines                   HelpFile                            Combining comman...
about_Preference_Variables        HelpFile                            Variables that c...
about_Remote                      HelpFile                            Describes how to...
about_Remote_Output               HelpFile                            Describes how to...
about_Sequence                    HelpFile                            Describes the Se...
about_Session_Configuration_Files HelpFile                            Describes sessio...
about_Variables                   HelpFile                            Describes how va...
about_Windows_PowerShell_5.0      HelpFile                            Describes new fe...
about_WQL                         HelpFile                            Describes WMI Qu...
about_WS-Management_Cmdlets       HelpFile                            Provides an over...
about_ForEach-Parallel            HelpFile                            Describes the Fo...
about_Parallel                    HelpFile                            Describes the Pa...
about_Sequence                    HelpFile                            Describes the Se...

使用 Help 來搜尋 process 傳回的 10 個結果,並使用它來搜尋 processes 傳回的 68 個結果。 如果只找到一個結果,則會顯示說明主題本身,而不是命令清單。

get-help *hotfix*
NAME
    Get-HotFix

SYNOPSIS
    Gets the hotfixes that have been applied to the local and remote computers.


SYNTAX
    Get-HotFix [-ComputerName <String[]>] [-Credential <PSCredential>] [-Description
    <String[]>] [<CommonParameters>]

    Get-HotFix [[-Id] <String[]>] [-ComputerName <String[]>] [-Credential
    <PSCredential>] [<CommonParameters>]


DESCRIPTION
    The Get-Hotfix cmdlet gets hotfixes (also called updates) that have been installed
    on either the local computer (or on specified remote computers) by Windows Update,
    Microsoft Update, or Windows Server Update Services; the cmdlet also gets hotfixes
    or updates that have been installed manually by users.


RELATED LINKS
    Online Version: http://go.microsoft.com/fwlink/?LinkId=821586
    Win32_QuickFixEngineering http://go.microsoft.com/fwlink/?LinkID=145071
    Get-ComputerRestorePoint
    Add-Content

REMARKS
    To see the examples, type: "get-help Get-HotFix -examples".
    For more information, type: "get-help Get-HotFix -detailed".
    For technical information, type: "get-help Get-HotFix -full".
    For online help, type: "get-help Get-HotFix -online"

現在,若要揭開 PowerShell 中只有説明主題的命令,才能揭開神話 Help

help *more*
NAME
    more

SYNTAX
    more [[-paths] <string[]>]


ALIASES
    None


REMARKS
    None

請注意,在上一個範例 more 中沒有說明主題,但 Help PowerShell 中的系統仍可找到。 它只找到一個相符專案,並傳回您在命令沒有說明主題時會看到的基本語法資訊。

PowerShell 包含許多概念性 (關於) 說明主題。 下列命令可用來傳回系統上所有 About 說明主題的清單。

help About_*

將結果限制為單一 [關於說明] 主題會顯示實際的幫助主題,而不是傳回清單。

help about_Updatable_Help

PowerShell 中的說明系統必須更新,才能 顯示 [關於 說明] 主題。 如果基於某些原因,說明系統的初始更新在您的電腦上失敗,則在 Cmdlet 成功執行之前 Update-Help ,將無法使用檔案。

Get-Command

Get-Command 是設計來協助您找出命令。 在沒有任何參數的情況下執行 Get-Command ,會傳回系統上所有命令的清單。 下列範例示範如何使用 Get-Command Cmdlet 來判斷使用行程時存在的命令:

Get-Command -Noun Process
CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Debug-Process                                      3.1.0.0    Microsof...
Cmdlet          Get-Process                                        3.1.0.0    Microsof...
Cmdlet          Start-Process                                      3.1.0.0    Microsof...
Cmdlet          Stop-Process                                       3.1.0.0    Microsof...
Cmdlet          Wait-Process                                       3.1.0.0    Microsof...

請注意,在先前執行所在的Get-Command範例中,會使用 Noun 參數,並Process指定為 Noun 參數的值。 如果您不知道如何使用 Cmdlet, Get-Command 該怎麼辦? 您可以使用 Get-Help 來顯示 的說明 Get-Command主題。

NameNounVerb 參數接受通配符。 下列範例顯示搭配 Name 參數使用的通配符:

Get-Command -Name *service*
CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Function        Get-NetFirewallServiceFilter                       2.0.0.0    NetSecurity
Function        Set-NetFirewallServiceFilter                       2.0.0.0    NetSecurity
Cmdlet          Get-Service                                        3.1.0.0    Microsof...
Cmdlet          New-Service                                        3.1.0.0    Microsof...
Cmdlet          New-WebServiceProxy                                3.1.0.0    Microsof...
Cmdlet          Restart-Service                                    3.1.0.0    Microsof...
Cmdlet          Resume-Service                                     3.1.0.0    Microsof...
Cmdlet          Set-Service                                        3.1.0.0    Microsof...
Cmdlet          Start-Service                                      3.1.0.0    Microsof...
Cmdlet          Stop-Service                                       3.1.0.0    Microsof...
Cmdlet          Suspend-Service                                    3.1.0.0    Microsof...
Application     AgentService.exe                                   10.0.14... C:\Windo...
Application     SensorDataService.exe                              10.0.14... C:\Windo...
Application     services.exe                                       10.0.14... C:\Windo...
Application     services.msc                                       0.0.0.0    C:\Windo...
Application     TieringEngineService.exe                           10.0.14... C:\Windo...

我不是搭配 Name 參數Get-Command使用通配符的粉絲,因為它也會傳回不是原生 PowerShell 命令的可執行檔。

如果您要搭配 Name 參數使用通配符,建議您使用 CommandType 參數來限制結果。

Get-Command -Name *service* -CommandType Cmdlet, Function, Alias

較佳的選項是使用 Verb 或 Noun 參數,或兩者兼有,因為只有 PowerShell 命令同時具有動詞和名詞。

發現幫助主題發生問題嗎? 好消息是 PowerShell 的說明主題已開放原始碼,且可在 GitHub 上的 PowerShell-Docs 存放庫中取得。 不僅為您自己修正了不正確的資訊,還能為其他人支付費用。 只要分支 GitHub 上的 PowerShell 檔存放庫、更新說明主題,然後提交提取要求。 一旦接受提取要求,即可供所有人使用更正的檔。

更新說明

先前已更新PowerShell說明主題的本機複本,要求命令的第一次說明。 建議您定期更新說明系統,因為可以不時更新說明內容。 Cmdlet Update-Help 可用來更新說明主題。 它預設需要因特網存取,而且您必須以系統管理員身分執行 PowerShell。

Update-Help
Update-Help : Failed to update Help for the module(s) 'BitsTransfer' with UI culture(s)
{en-US} : Unable to retrieve the HelpInfo XML file for UI culture en-US. Make sure the HelpInfoUri
property in the module manifest is valid or check your network connection and then try the command again.
At line:1 char:1
+ Update-Help
+
    + CategoryInfo          : InvalidOperation: (:) [Update-Help], Exception
    + FullyQualifiedErrorId : InvalidHelpInfoUri,Microsoft.PowerShell.Commands.UpdateHel
   pCommand

Update-Help : Failed to update Help for the module(s) 'NetworkControllerDiagnostics,
StorageReplica' with UI culture(s) {en-US} : Unable to retrieve the HelpInfo XML file
for UI culture en-US. Make sure the HelpInfoUri property in the module manifest is valid
or check your network connection and then try the command again.
At line:1 char:1
+ Update-Help
+
    + CategoryInfo          : ResourceUnavailable: (:) [Update-Help], Exception
    + FullyQualifiedErrorId : UnableToRetrieveHelpInfoXml,Microsoft.PowerShell.Commands.
   UpdateHelpCommand

有幾個模組傳回錯誤,這並不罕見。 如果計算機沒有因特網存取權,您可以使用 Save-Help 另一部具有因特網存取權的 Cmdlet,先將更新的說明資訊儲存到您網路上的檔案共享,然後使用 的 SourcePath 參數 Update-Help 來指定說明主題的這個網路位置。

請考慮在PowerShell中設定排程工作或將一些邏輯新增至配置檔腳本,以定期更新電腦上的說明內容。 配置檔文本將在即將推出的章節中討論。

摘要

在本章中,您已瞭解如何使用 Get-HelpGet-Command尋找命令。 您已瞭解如何使用說明系統來找出如何在找到命令之後使用命令。 您也已瞭解如何在有更新時更新說明主題的內容。

我面臨的挑戰是每天學習 PowerShell 命令。

Get-Command | Get-Random | Get-Help -Full

檢閱

  1. Positional 的 Get-Service DisplayName 參數嗎?
  2. Cmdlet 有多少 Get-Process 個參數集?
  3. 使用事件記錄檔時有哪些 PowerShell 命令?
  4. 傳回電腦上執行的PowerShell進程清單的PowerShell命令為何?
  5. 如何更新儲存在電腦上的PowerShell說明內容?

如果您想要瞭解本章所涵蓋主題的詳細資訊,建議您閱讀下列 PowerShell 說明主題。

在下一章中,您將瞭解 Get-Member Cmdlet 以及物件、屬性和方法。