Advanced Windows PowerShell Scripting Video Training

Advanced Windows PowerShell Scripting Video Training
Advanced Windows PowerShell Scripting Video Training

Sunday, January 24, 2016

Reading Help Files (Part 5 of 7)

The full help file for any cmdlet is the golden ticket to getting the PowerShell pipeline to work.  Go ahead and get the full help file for Stop-Process.

Get-Help Stop-Process –Full

The full help file contains everything.  Let’s look at some of the differences between Full and Detailed help.

The first difference is with the parameters section.  Extra data is displayed for each parameter.

        Specifies the process IDs of the processes to be stopped. To specify multiple IDs, use commas to separate the IDs. To find the PID of a process, type
        "get-process". The parameter name ("Id") is optional.
        Required?                    true
        Position?                    1
        Default value                none
        Accept pipeline input?       true (ByPropertyName)
        Accept wildcard characters?  false

The Required attribute tells us if this is a mandatory parameter.

Position will let you know if this is a positional parameter or a named parameter.  In this case, let’s stop the process with an ID of 6944.  Since the ID parameter is positional, we can accomplish this in one of two ways.

Stop-Process –ID 6924
Stop-Process 6924

With positional parameters, you can omit the parameter name as long as you provide a value of the correct data type.  If the parameter is named, you must provide the parameters name to use it.  In this case, -ID­ is in position #1.

The Default value will tell me if a default value is provided if I do not specify one.  Ypu will find that many cmdlets with a –ComputerName parameter has a default value of LocalHost.

We use the Accept pipeline input attribute to determine if we can use the PowerShell pipeline with this parameter.  In this case, we can.

The final attribute tells us if a wild card is accepted for the argument of this parameter.  In this case, no it is not.

Next is the INPUTS and OUTPUTS:
        You can pipe a process object to Stop-Process.
    None or System.Diagnostics.Process
        When you use the PassThru parameter, Stop-Process returns a System.Diagnostics.Process object that represents the stopped process. Otherwise, this
        cmdlet does not generate any output.

This section tells us what kind of object can be passed to this cmdlet and what we should expect out of it.

The NOTES section provides extra information that may not fall under any of the other categories.
        You can also refer to Stop-Process by its built-in aliases, "kill" and "spps". For more information, see about_Aliases.
        You can also use the properties and methods of the Windows Management Instrumentation (WMI) Win32_Process object in Windows PowerShell. For more
        information, see Get-WmiObject and the WMI SDK.
        When stopping processes, be aware that stopping a process can stop process and services that depend on the process. In an extreme case, stopping a
        process can stop Windows.

Tomorrow we will wrap things up with regards to cmdlets with a few extra tips.

No comments: