PowerShell Help

 

Der wohl wichtigste PowerShell-Befehl ist Get-Help. Mit Get-Help kann die integrierte PowerShell-Hilfe aufgerufen werden, sie gibt einen Überblick über die Funktion der einzelnen Befehle und deren Anwendung, bis hin zu konkreten Beispielen.

Beim ersten Start der Hilfe-Funktion (Get-Help) wird diese über den Befehl Update-Help aus dem Internet nachgeladen. (Seit Version 3.0 ist die Hilfe nicht mehr Bestandteil des Betriebssystems)

Update-help lädt bei vorhandenem Internet alle notwendigen Hilfedateien herunter:

Hilfe zu einem bestimmten Befehl

Get-Help CommandName. Als Befehl verwende ich in den folgenden Beispielen den Befehl Get-Command. Get-Command listet alle verfügbaren Befehle auf und kann bei der Suche nach einem bestimmten Befehl verwendet werden. Wenn also gar nicht klar ist wie ein Befehl heißt, kann dieser mit Get-Command gesucht und im Anschluss mit Get-Help dessen Hilfe aufgerufen werden.

Um als Beispiele eine Hilfe zum Befehl Get-Command zu bekommen, kann dies mittels

get-help get-command

oder einfach mit

get-command -?

Als Beispiel für die Anzeige der Hilfe für den Befehl get-command:

[+]
C:\>  get-help get-command

NAME
    Get-Command

ÜBERSICHT
    Gets all commands.


SYNTAX
    Get-Command [[-Name] <System.String[]>] [[-ArgumentList] <System.Object[]>] [-All] [-CommandType {Alias | Function
    | Filter | Cmdlet | ExternalScript | Application | Script | Workflow | Configuration | All}]
    [-FullyQualifiedModule <Microsoft.PowerShell.Commands.ModuleSpecification[]>] [-ListImported] [-Module
    <System.String[]>] [-ParameterName <System.String[]>] [-ParameterType <System.Management.Automation.PSTypeName[]>]
    [-ShowCommandInfo] [-Syntax] [-TotalCount <System.Int32>] [<CommonParameters>]

    Get-Command [[-ArgumentList] <System.Object[]>] [-All] [-FullyQualifiedModule
    <Microsoft.PowerShell.Commands.ModuleSpecification[]>] [-ListImported] [-Module <System.String[]>] [-Noun
    <System.String[]>] [-ParameterName <System.String[]>] [-ParameterType <System.Management.Automation.PSTypeName[]>]
    [-ShowCommandInfo] [-Syntax] [-TotalCount <System.Int32>] [-Verb <System.String[]>] [<CommonParameters>]


BESCHREIBUNG
    The `Get-Command` cmdlet gets all commands that are installed on the computer, including cmdlets, aliases,
    functions, filters, scripts, and applications. `Get-Command` gets the commands from PowerShell modules and
    commands that were imported from other sessions. To get only commands that have been imported into the current
    session, use the ListImported parameter.

    Without parameters, `Get-Command` gets all of the cmdlets, functions, and aliases installed on the computer.
    `Get-Command *` gets all types of commands, including all of the non-PowerShell files in the Path environment
    variable (`$env:Path`), which it lists in the Application command type.

    `Get-Command` that uses the exact name of the command, without wildcard characters, automatically imports the
    module that contains the command so that you can use the command immediately. To enable, disable, and configure
    automatic importing of modules, use the `$PSModuleAutoLoadingPreference` preference variable. For more
    information, see about_Preference_Variables (About/about_Preference_Variables.md).

    `Get-Command` gets its data directly from the command code, unlike `Get-Help`, which gets its information from
    help topics.

    Starting in Windows PowerShell 5.0, results of the `Get-Command` cmdlet display a Version column by default. A new
    Version property has been added to the CommandInfo class.


VERWANDTE LINKS
    Online Version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/get-command?view=powershell-
    5.1&WT.mc_id=ps-gethelp
    Export-PSSession
    Get-Help
    Get-Member
    Get-PSDrive
    Import-PSSession
    about_Command_Precedence

HINWEISE
    Zum Aufrufen der Beispiele geben Sie Folgendes ein: "get-help Get-Command -examples".
    Weitere Informationen erhalten Sie mit folgendem Befehl: "get-help Get-Command -detailed".
    Technische Informationen erhalten Sie mit folgendem Befehl: "get-help Get-Command -full".
    Geben Sie zum Abrufen der Onlinehilfe Folgendes ein: "get-help Get-Command -online"

Hilfe Beispiele

Beispiele zu einem Befehl können mittels get-help command -examples angezeigt werden, hier wieder als Beispiel unser Befehl get-command

[+]
PS P:\> get-help get-command -examples

NAME
    Get-Command

ÜBERSICHT
    Gets all commands.


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

    Get-Command


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

    Get-Command -ListImported


    ------- Example 3: Get cmdlets and display them in order -------

    Get-Command -Type Cmdlet | Sort-Object -Property Noun | Format-Table -GroupBy Noun


    ------------- Example 4: Get commands in a module -------------

    Get-Command -Module Microsoft.PowerShell.Security, Microsoft.PowerShell.Utility


    ---------- Example 5: Get information about a cmdlet ----------

    Get-Command Get-AppLockerPolicy

    When a module is imported automatically, the effect is the same as using the Import-Module cmdlet. The module can
    add commands, types and formatting files, and run scripts in the session. To enable, disable, and configuration
    automatic importing of modules, use the `$PSModuleAutoLoadingPreference` preference variable. For more
    information, see about_Preference_Variables (../Microsoft.PowerShell.Core/About/about_Preference_Variables.md).
    ------------ Example 6: Get the syntax of a cmdlet ------------

    Get-Command  -Name Get-Childitem -Args Cert: -Syntax

    When you compare the syntax displayed in the output with the syntax that is displayed when you omit the Args (
    ArgumentList ) parameter, you'll see that the Certificate provider adds a dynamic parameter, CodeSigningCert , to
    the `Get-ChildItem` cmdlet.

    For more information about the Certificate provider, see about_Certificate_Provider
    (../Microsoft.PowerShell.Security/About/about_Certificate_Provider.md).
    -------------- Example 7: Get dynamic parameters --------------

    function Get-DynamicParameters
    {
        param ($Cmdlet, $PSDrive)
        (Get-Command -Name $Cmdlet -ArgumentList $PSDrive).ParameterSets |
          ForEach-Object {$_.Parameters} |
            Where-Object { $_.IsDynamic } |
              Select-Object -Property Name -Unique
    }
    Get-DynamicParameters -Cmdlet Get-ChildItem -PSDrive Cert:

    Name
    ----
    CodeSigningCert

    The `Get-DynamicParameters` function in this example gets the dynamic parameters of a cmdlet. This is an
    alternative to the method used in the previous example. Dynamic parameter can be added to a cmdlet by another
    cmdlet or a provider.
    ----------- Example 8: Get all commands of all types -----------

    Get-Command *

    It returns an ApplicationInfo object (System.Management.Automation.ApplicationInfo) for each file, not a FileInfo
    object (System.IO.FileInfo).
    -- Example 9: Get cmdlets by using a parameter name and type --

    Get-Command -ParameterName *Auth* -ParameterType AuthenticationMechanism

    You can use a command like this one to find cmdlets that let you specify the method that is used to authenticate
    the user.

    The ParameterType parameter distinguishes parameters that take an AuthenticationMechanism value from those that
    take an AuthenticationLevel parameter, even when they have similar names.
    ------------------- Example 10: Get an alias -------------------

    Get-Command -Name dir

    CommandType     Name                                               ModuleName
    -----------     ----                                               ----------
    Alias           dir -> Get-ChildItem

    Although it is typically used on cmdlets and functions, `Get-Command` also gets scripts, functions, aliases, and
    executable files.

    The output of the command shows the special view of the Name property value for aliases. The view shows the alias
    and the full command name.
    ----- Example 11: Get all instances of the Notepad command -----

    Get-Command Notepad -All | Format-Table CommandType, Name, Definition

    CommandType     Name           Definition
    -----------     ----           ----------
    Application     notepad.exe    C:\WINDOWS\system32\notepad.exe
    Application     NOTEPAD.EXE    C:\WINDOWS\NOTEPAD.EXE

    The All parameter is useful when there is more than one command with the same name in the session.

    Beginning in Windows PowerShell 3.0, by default, when the session includes multiple commands with the same name,
    `Get-Command` gets only the command that runs when you type the command name. With the All parameter,
    `Get-Command` gets all commands with the specified name and returns them in execution precedence order. To run a
    command other than the first one in the list, type the fully qualified path to the command.

    For more information about command precedence, see about_Command_Precedence (About/about_Command_Precedence.md).
    - Example 12: Get the name of a module that contains a cmdlet -

    (Get-Command Get-Date).ModuleName

    Microsoft.PowerShell.Utility

    This command format works on commands in PowerShell modules, even if they are not imported into the session.
    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 return.

    The first part of the command gets all cmdlets. A pipeline operator (`|`) sends the cmdlets to the `Where-Object`
    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 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.

Update-Help ohne Internetverbindung

Um die PowerShell-Hilfe auf einem Computer ohne Internet zu installieren, kann diese vorab auf einem Internet-fähigen Gerät exportiert und im Anschluß auf den Pc ohne Internet importiert werden:

Exportieren der Hilfe:

PS C:\> Save-Help -DestinationPath c:\pshelp -Module * -Force -UICulture "en-us"

Importieren der Hilfe auf einem Zielrechner ohne Internet:

PS C:\Windows\system32> update-help -SourcePath c:\pshelp -Module * -force

PowerShell Hilfe in einem selbst erstellten Cmdlet

siehe:  PowerShell Cmdlet Hilfe

positive Bewertung({{pro_count}})
Beitrag bewerten:
{{percentage}} % positiv
negative Bewertung({{con_count}})

DANKE für deine Bewertung!

Aktualisiert: 04.04.2023 von Bernhard | Translation English |🔔 | Kommentare:1

Grundlagen | Powershell Befehle in der Konsole

Fragen / Kommentare


(sortiert nach Bewertung / Datum) [alle Kommentare(neueste zuerst)]

✍anonym
12.03.2020 17:00
User: Florian 
Hallo, ich habe etwas gegooglet, bekomme aber keine hilfreichen Infos. Und zwar bekomme ich, für die command -? eine sehr stark abgespeckte Version der Syntax, keine Befehlsbeschreibungen und so weiter. Es steht die Hilfedateien seien nicht auf meinem Computer und ich soll Update-Help ausführen. Habe dies gemacht er läd und sucht eine Weile und failed dann komplett. Könnt Ihr mir vllt helfen?
Großes Lob an diese Übersicht habe sehr lang nach hilfreichen Infos zum Umgang mit der Powershell gesucht, bin nicht mal auf der Referenzseite von Microsoft fündig geworden. Könntet Ihr mir vllt auch erklären, wieso ich dazu nichts finde, bzw. wie ich die Infos bekomme, die ich brauche? Ich kann mir vorstellen, dass ist immer individuell, aber es gibt bestimmt ein paar Dinge auf die ich achten kann.

Mit freundlichen Grüßen,
Florian