-
Book Overview & Buying
-
Table Of Contents
Instant Windows PowerShell Guide
By :
We will learn about the parameters of Get-Command in different versions of PowerShell.
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.
Execute the following commands:
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
The following command statement retrieves all the CMDLETs that have the ComputerName parameter:
PS C :\> Get-Command -ParameterName ComputerName
The following command statement retrieves all the CMDLETs that accept the PSCredential parameter type.
PS C :\> Get-Command -ParameterType PSCredential
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.
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.
As stated in earlier recipes, Windows PowerShell 4.0 has a new feature called Desired State Configuration (DSC).
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.
Change the font size
Change margin width
Change background colour