PowerShellでコマンドのヘルプを開く方法

Powershell Powershell

Powershellを利用する際にコマンドのヘルプを開く方法をまとめました。

広告

help [コマンド名] で表示可能

ヘルプの表示には help コマンドを利用します。
コマンドプロンプトでは引数としてではなくコマンドとして用意されています。

Get-Commandのヘルプを見る

まず、コマンド一覧を取得するコマンド(Get-Command)のヘルプを確認してみます。

help Get-Command

・実行結果

PS C:\> help Get-Command

名前
    Get-Command

概要
    Gets all commands.


構文
    Get-Command [[-Name] <System.String[]>] [[-ArgumentList] <System.Object[]>] [-All] [-CommandType {Alias | F
    unction | Filter | Cmdlet | ExternalScript | Application | Script | Workflow | Configuration | All}] [-Full
    yQualifiedModule <Microsoft.PowerShell.Commands.ModuleSpecification[]>] [-ListImported] [-Module <System.St
    ring[]>] [-ParameterName <System.String[]>] [-ParameterType <System.Management.Automation.PSTypeName[]>] [-
    ShowCommandInfo] [-Syntax] [-TotalCount <System.Int32>] [<CommonParameters>]

    Get-Command [[-ArgumentList] <System.Object[]>] [-All] [-FullyQualifiedModule <Microsoft.PowerShell.Command
    s.ModuleSpecification[]>] [-ListImported] [-Module <System.String[]>] [-Noun <System.String[]>] [-Parameter
    Name <System.String[]>] [-ParameterType <System.Management.Automation.PSTypeName[]>] [-ShowCommandInfo] [-S
    yntax] [-TotalCount <System.Int32>] [-Verb <System.String[]>] [<CommonParameters>]

 ~~~<中略>~~~

注釈
    例を参照するには、次のように入力してください: "get-help Get-Command -examples".
    詳細を参照するには、次のように入力してください: "get-help Get-Command -detailed".
    技術情報を参照するには、次のように入力してください: "get-help Get-Command -full".
    オンライン ヘルプを参照するには、次のように入力してください: "get-help Get-Command -online"



PS C:\>

コマンドの利用例を参照する

上記の結果の中の「注釈」にも記載がある通り以下のコマンドで例を参照することが可能です。

get-help Get-Command -examples

・実行結果

PS C:\> get-help Get-Command -examples

名前
    Get-Command

概要
    Gets all commands.


    -------- Example 1: Get cmdlets, functions, and aliases --------

    Get-Command


    -------- Example 2: Get commands in the current session --------

    Get-Command -ListImported


       ~~~<中略>~~~


    Example 13: Get cmdlets and functions that have an output type

    Get-Command -Type Cmdlet | Where-Object OutputType | Format-List -Property Name, OutputType

    This command gets the cmdlets and functions that have an output type and the type of objects that they retu
    rn.

    The first part of the command gets all cmdlets. A pipeline operator (`|`) sends the cmdlets to the `Where-O
    bject` cmdlet, which selects only the ones in which the OutputType property is populated. Another pipeline
    operator sends the selected cmdlet objects to the `Format-List` cmdlet, which displays the name and output
    type of each cmdlet in a list.

    The OutputType property of a CommandInfo object has a non-null value only when the cmdlet code defines the
    OutputType attribute for the cmdlet.
    Example 14: Get cmdlets that take a specific object type as input

    Get-Command -ParameterType (((Get-NetAdapter)[0]).PSTypeNames)

    CommandType     Name                                               ModuleName
    -----------     ----                                               ----------
    Function        Disable-NetAdapter                                 NetAdapter
    Function        Enable-NetAdapter                                  NetAdapter
    Function        Rename-NetAdapter                                  NetAdapter
    Function        Restart-NetAdapter                                 NetAdapter
    Function        Set-NetAdapter                                     NetAdapter

    This command finds cmdlets that take net adapter objects as input. You can use this command format to find
    the cmdlets that accept the type of objects that any command returns.

    The command uses the PSTypeNames intrinsic property of all objects, which gets the types that describe the
    object. To get the PSTypeNames property of a net adapter, and not the PSTypeNames property of a collection
    of net adapters, the command uses array notation to get the first net adapter that the cmdlet returns. To g
    et the PSTypeNames property of a net adapter, and not the PSTypeNames property of a collection of net adapt
    ers, the command uses array notation to get the first net adapter that the cmdlet returns.



PS C:\>

このようにコマンドの利用例が表示されます。
Get-Comand では13個の例が表示されました。

広告

その他の利用例

cd コマンドのヘルプを見る

よく利用するディレクトリの変更コマンド [cd] コマンドのヘルプを確認してみます。

PS C:\> help cd

名前
    Set-Location

概要
    Sets the current working location to a specified location.


構文
    Set-Location -LiteralPath <System.String> [-PassThru] [-UseTransaction] [<CommonParameters>]

    Set-Location [[-Path] <System.String>] [-PassThru] [-UseTransaction] [<CommonParameters>]

    Set-Location [-PassThru] [-StackName <System.String>] [-UseTransaction] [<CommonParameters>]


説明
    The `Set-Location` cmdlet sets the working location to a specified location. That location could be a directory, a subdirectory, a registry locat
    ion, or any provider path.

    You can also use the StackName parameter to make a named location stack the current location stack. For more information about location stacks, s
    ee the Notes.


関連するリンク
    Online Version: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/set-location?view=powershell-5.1&WT.mc_id=ps-gethel
    p
    Get-Location
    Pop-Location
    Push-Location

注釈
    例を参照するには、次のように入力してください: "get-help Set-Location -examples".
    詳細を参照するには、次のように入力してください: "get-help Set-Location -detailed".
    技術情報を参照するには、次のように入力してください: "get-help Set-Location -full".
    オンライン ヘルプを参照するには、次のように入力してください: "get-help Set-Location -online"



PS C:\>

select-string コマンドのヘルプを見る

次に select-string コマンドのヘルプを確認してみます。

PS C:\> help select-string

名前
    Select-String

概要
    Finds text in strings and files.


構文
    Select-String [-Pattern] <System.String[]> [-AllMatches] [-CaseSensitive] [-Context <System.Int32[]>] [-Encoding {ASCII | BigEndianUnicode | Defa
    ult | OEM | Unicode | UTF7 | UTF8 | UTF32}] [-Exclude <System.String[]>] [-Include <System.String[]>] -InputObject <System.Management.Automation.
    PSObject> [-List] [-NotMatch] [-Quiet] [-SimpleMatch] [<CommonParameters>]

    Select-String [-Pattern] <System.String[]> [-AllMatches] [-CaseSensitive] [-Context <System.Int32[]>] [-Encoding {ASCII | BigEndianUnicode | Defa
    ult | OEM | Unicode | UTF7 | UTF8 | UTF32}] [-Exclude <System.String[]>] [-Include <System.String[]>] [-List] -LiteralPath <System.String[]> [-No
    tMatch] [-Quiet] [-SimpleMatch] [<CommonParameters>]

    Select-String [-Pattern] <System.String[]> [-Path] <System.String[]> [-AllMatches] [-CaseSensitive] [-Context <System.Int32[]>] [-Encoding {ASCII
     | BigEndianUnicode | Default | OEM | Unicode | UTF7 | UTF8 | UTF32}] [-Exclude <System.String[]>] [-Include <System.String[]>] [-List] [-NotMatc
    h] [-Quiet] [-SimpleMatch] [<CommonParameters>]


説明
    The `Select-String` cmdlet uses regular expression matching to search for text patterns in input strings and files. You can use `Select-String` s
    imilar to `grep` in UNIX or `findstr.exe` in Windows.

    `Select-String` is based on lines of text. By default, `Select-String` finds the first match in each line and, for each match, it displays the fi
    le name, line number, and all text in the line containing the match. You can direct `Select-String` to find multiple matches per line, display te
    xt before and after the match, or display a Boolean value (True or False) that indicates whether a match is found.

    `Select-String` can display all the text matches or stop after the first match in each input file. `Select-String` can be used to display all tex
    t that doesn't match the specified pattern.

    You can also specify that `Select-String` should expect a particular character encoding, such as when you're searching files of Unicode text. `Se
    lect-String` uses the byte-order-mark (BOM) to detect the encoding format of the file. If the file has no BOM, it assumes the encoding is UTF8.


関連するリンク
    Online Version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/select-string?view=powershell-5.1&WT.mc_id=ps-gethelp
    about_Automatic_Variables
    about_Comparison_Operators
    about_Functions
    about_Quoting_Rules
    about_Regular_Expressions
    Get-Alias
    Get-ChildItem
    Get-Command
    Get-Member
    Get-WinEvent
    Out-File

注釈
    例を参照するには、次のように入力してください: "get-help Select-String -examples".
    詳細を参照するには、次のように入力してください: "get-help Select-String -detailed".
    技術情報を参照するには、次のように入力してください: "get-help Select-String -full".
    オンライン ヘルプを参照するには、次のように入力してください: "get-help Select-String -online"



PS C:\>

コメント

タイトルとURLをコピーしました