Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Instant Windows PowerShell Guide

You're reading from   Instant Windows PowerShell Guide Enhance your knowledge of Windows PowerShell and get to grips with its latest features

Arrow left icon
Product type Paperback
Published in Nov 2013
Publisher Packt
ISBN-13 9781849686785
Length 86 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Harshul Patel Harshul Patel
Author Profile Icon Harshul Patel
Harshul Patel
Arrow right icon
View More author details
Toc

Working with the various parameters of Get-Command (Intermediate)


We will learn about the parameters of Get-Command in different versions of PowerShell.

Getting ready

In PowerShell v2.0, Get-Command only retrieves the CMDLETs available in the present session whereas, in v3.0, it retrieves all the CMDLETs that are installed on the local computer, including modules, functions, workflows, scripts, and so on. It also includes the application in the output available at the $env:Path location.

How to do it...

Execute the following commands:

  1. The following command statements retrieve a list of the workflow CMDLETs and general functions available in the current session:

    PS C :\> Get-Command -Module PSWorkflow
    PS C :\> Get-Command -CommandType Function
    
  2. The following command statement retrieves all the CMDLETs that have the ComputerName parameter:

    PS C :\> Get-Command -ParameterName ComputerName 
    
  3. The following command statement retrieves all the CMDLETs that accept the PSCredential parameter type.

    PS C :\> Get-Command -ParameterType PSCredential
    

How it works...

The following are the newly introduced parameters in PowerShell v3.0 with Get-Command:

  • -All: This parameter helps us retrieve all the CMDLETs, irrespective of conflicting names.

  • -CommandType<CommandTypes>: With this parameter, we can now get the command list by mentioning CommandType explicitly. We can have other CommandTypes, such as ExternalScript, Application, and so on.

  • -ListImported [<SwitchParameter>]: Get-Command, along with the –ListImported parameter, gets the list of CMDLETs available in the current console session. By default, Get-Command retrieves the CMDLETs from all the sessions that are present on the local computer.

  • -ParameterName <String[]>: This parameter helps us retrieve a list of CMDLETs with the specified parameter name in their syntax.

  • -ParameterType <PSTypeName[]>: This parameter helps us retrieve the list of CMDLETs that have the specified parameter type in their syntax.

Tip

For fast typing you can use the # tag to refer to a CMDLET in the command history. For example:

PS C :\> Get-Process
PS C :\> #Get <Tab>

The preceding command statement searches for the Get keyword in the console command history and refers to the matching CMDLET for tab completion. In this case, the Get keyword matches Get-Process and, hence, upon execution, retrieves a list of the running processes.

There's more…

As stated in earlier recipes, Windows PowerShell 4.0 has a new feature called Desired State Configuration (DSC).

Getting the Configuration type CMDLETs

There are a few CMDLETs with the Configuration command types. To retrieve the Configuration command type CMDLETs, run the following command:

PS C :\> Get-Command -CommandType Configuration

Prior to using the preceding command, the DSC feature should be installed in your local server.

You have been reading a chapter from
Instant Windows PowerShell Guide
Published in: Nov 2013
Publisher: Packt
ISBN-13: 9781849686785
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image