jskfan
asked on
how to get help in Powershell while writing commands.
how to get help in Powershell while writing commands.
when writing commands in windows there is always the "/?" , to see what can come after the last typed command.
example :
then you type for example :
then you can type:
Until you find the parameters you need to compose the Full command.
in Powershell , I do not see the help as long as you are type the command ... I wonder if there is anyway to find that help similar to writing commands in Windows CLI as the examples I cited above ?
Thank you
when writing commands in windows there is always the "/?" , to see what can come after the last typed command.
example :
C:\>wmic /?
WMIC is deprecated.
[global switches] <command>
The following global switches are available:
/NAMESPACE Path for the namespace the alias operate against.
/ROLE Path for the role containing the alias definitions.
/NODE Servers the alias will operate against.
/IMPLEVEL Client impersonation level.
/AUTHLEVEL Client authentication level.
/LOCALE Language id the client should use.
/PRIVILEGES Enable or disable all privileges.
then you type for example :
C:\>wmic bios /?
BIOS - Basic input/output services (BIOS) management.
HINT: BNF for Alias usage.
(<alias> [WMIObject] | <alias> [<path where>] | [<alias>] <path where>) [<verb clause>].
USAGE:
BIOS ASSOC [<format specifier>]
BIOS CREATE <assign list>
BIOS DELETE
BIOS GET [<property list>] [<get switches>]
BIOS LIST [<list format>] [<list switches>]
then you can type:
C:\>wmic bios get /?
Property get operations.
USAGE:
GET [<property list>] [<get switches>]
NOTE: <property list> ::= <property name> | <property name>, <property list>
The following properties are available:
Property Type Operation
======== ==== =========
BiosCharacteristics N/A N/A
BuildNumber N/A N/A
CodeSet N/A N/A
CurrentLanguage N/A N/A
Description N/A N/A
IdentificationCode N/A N/A
InstallDate N/A N/A
InstallableLanguages N/A N/A
LanguageEdition N/A N/A
ListOfLanguages N/A N/A
Manufacturer N/A N/A
Name N/A N/A
Until you find the parameters you need to compose the Full command.
in Powershell , I do not see the help as long as you are type the command ... I wonder if there is anyway to find that help similar to writing commands in Windows CLI as the examples I cited above ?
Thank you
Most important command since PS 3.0, in an administrative console:
Update-Help
There's also (since PS 3.0) the possibility to show the help in a GUI window, including a string search function:
Get-Help -ShowWindow Some-Command
And another little-known but helpful command:
Show-Command Some-Command
Or when you start with a new module, and want to quickly search/filter available commands, get commands by the module name and pipe them to Out-GridView:
Get-Command -Module Microsoft.PowerShell.Manag ement | Out-GridView
Update-Help
There's also (since PS 3.0) the possibility to show the help in a GUI window, including a string search function:
Get-Help -ShowWindow Some-Command
And another little-known but helpful command:
Show-Command Some-Command
Or when you start with a new module, and want to quickly search/filter available commands, get commands by the module name and pipe them to Out-GridView:
Get-Command -Module Microsoft.PowerShell.Manag
Depending on your PS environment, following the command (and space), you can type a hyphen character and press the tab key. This should display the parameters of the command.
Example:
pressing the tab key changes the command line to read:
This sequence iterates the parameters and wraps around to the beginning (-Path).
If you type one or more characters after the hyphen, you will be shown a list of parameters that begin with that/those characters.
Example:
cycles through
Something similar happens if you type a period after an object and then press the tab key. Methods and properties will be iterated.
Example:
gci -
pressing the tab key changes the command line to read:
gci -Path
gci -LiteralPath
gci -Filter
gci -Include
gci -Exclude
gci -Recurse
gci -Depth
gci -Force
gci -Name
This sequence iterates the parameters and wraps around to the beginning (-Path).
If you type one or more characters after the hyphen, you will be shown a list of parameters that begin with that/those characters.
Example:
gci -p
cycles through
gci -Path
gci -PSPath
gci -PipelineVariable
gci -pv
before wrapping back around to -Path.Something similar happens if you type a period after an object and then press the tab key. Methods and properties will be iterated.
ASKER
I guess you will have to know the whole command from end to end before you type it.
no sure you can memorize the commands without Google help.
no sure you can memorize the commands without Google help.
If you are running the PS ISE, you can open the commands window/panel, analogous to the show-command command. There is both description and a (details) UI for the parameters.
wmic is not really representative for command line utilities.
In PowerShell, you have cmdlets or functions, which are always built as <Verb>-<Noun>
<Verb> is somewhat restricted to avoid confusion:
Approved Verbs for PowerShell Commands
https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/approved-verbs-for-windows-powershell-commands?view=powershell-6
There aren't several hundred or thousand executable files with names nobody can associate by name with a certain function, like awk, grep, sed, ...
When PowerShell was developed, one of the main goals was discoverability, hence the "oh so long" names.
You want to do something with WMI?
Get-Command -Name *WMI*
This will even reveal wmic.exe
Want to restrict to plain PS:
Get-Command -Name *WMI* -CommandType Cmdlet, Function
You want to "get" something from WMI? Well, chances are it's Get-SomethingWMISomething. Since you know it's PS you want, you can use the -Verb and -Noun arguments:
Get-Command -Verb Get -Noun *WMI*
To get the arguments for a cmdlet, use one of the many possibilities mentioned above, first of all Get-Help.
You can actually pipe the results directly to Get-Help:
Get-Command -Verb Get -Noun *WMI* | Get-Help -ShowWindow
So, no, you don't have to memorize whole commands. All you have to memorize is how to find commands, and how to reveal their help.
It doesn't get any easier than in PowerShell.
In PowerShell, you have cmdlets or functions, which are always built as <Verb>-<Noun>
<Verb> is somewhat restricted to avoid confusion:
Approved Verbs for PowerShell Commands
https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/approved-verbs-for-windows-powershell-commands?view=powershell-6
There aren't several hundred or thousand executable files with names nobody can associate by name with a certain function, like awk, grep, sed, ...
When PowerShell was developed, one of the main goals was discoverability, hence the "oh so long" names.
You want to do something with WMI?
Get-Command -Name *WMI*
This will even reveal wmic.exe
Want to restrict to plain PS:
Get-Command -Name *WMI* -CommandType Cmdlet, Function
You want to "get" something from WMI? Well, chances are it's Get-SomethingWMISomething.
Get-Command -Verb Get -Noun *WMI*
To get the arguments for a cmdlet, use one of the many possibilities mentioned above, first of all Get-Help.
You can actually pipe the results directly to Get-Help:
Get-Command -Verb Get -Noun *WMI* | Get-Help -ShowWindow
So, no, you don't have to memorize whole commands. All you have to memorize is how to find commands, and how to reveal their help.
It doesn't get any easier than in PowerShell.
ASKER
for instance :
Get-ChildItem -Path ?
it does not give you what to type type after Path keyword.
not like command line, it will give the parameters that you can type after the last keyword . Example in CLI
you type the command Dir /? , it gives you keywords that you can type after Dir, if you select Dir /T ? , it will give you other keywords that are available after the "T" keyword.
in Powershell if you type :
Get-ChildItem -?
it gives the keywords that you can type after Get-ChildItem
if you type : Get-ChildItem -Path -?
it still gives you just the keywords you can type after Get-ChildItem and not the keywords that you should type after Path
Get-ChildItem -Path ?
it does not give you what to type type after Path keyword.
not like command line, it will give the parameters that you can type after the last keyword . Example in CLI
you type the command Dir /? , it gives you keywords that you can type after Dir, if you select Dir /T ? , it will give you other keywords that are available after the "T" keyword.
in Powershell if you type :
Get-ChildItem -?
it gives the keywords that you can type after Get-ChildItem
if you type : Get-ChildItem -Path -?
it still gives you just the keywords you can type after Get-ChildItem and not the keywords that you should type after Path
That is where the help command comes in, as described by Qlemo above.
What you're expecting is a setup where each cmdlet would have to implement its own help; this is obviously the only way for a stand-alone exe, but utterly pointless for a completely integrated interactive shell and scripting system like PowerShell with several thousand cmdlets, not to mention self-developed modules and functions.
There is one all-purpose cmdlet "Get-Help", which makes sure each cmdlet's help has the same basic information, is formatted the same way, can be searched the same way.
So as described several times, use Get-Help <CmdletName>.
Get-Help -ShowWindow Get-ChildItem will open a window which lists and describes all possible arguments for Get-ChildItem.
Or for just the help for the Path argument:
Get-Help Get-ChildItem -Parameter Path
There is one all-purpose cmdlet "Get-Help", which makes sure each cmdlet's help has the same basic information, is formatted the same way, can be searched the same way.
So as described several times, use Get-Help <CmdletName>.
Get-Help -ShowWindow Get-ChildItem will open a window which lists and describes all possible arguments for Get-ChildItem.
Or for just the help for the Path argument:
Get-Help Get-ChildItem -Parameter Path
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you Guys !!
I believe Powershell Help will Help someone who has experience with Powershell..
for a Beginner , it is nice to get familiarized with Powershell by reading , watching videos and practicing, and looking online ...
I believe Powershell Help will Help someone who has experience with Powershell..
for a Beginner , it is nice to get familiarized with Powershell by reading , watching videos and practicing, and looking online ...
To go thru command or parameter names, or to add a folder/file name, just type in the start and then use TAB to complete that part.
If you need more help, use get-help -online xyz to get a complete, exhaustive description of command xyz in a browser window (because of -online).
The full description as text in the console window is displayed with get-help -full xyz
if you want to see what is available as command with a particular noun, verb or parameter name, there are a lot more ways. E.g. you can use get-command *-item* to get a short list of commands having item in their name.
Or use get-help *ScriptBlock* for listing commands mentioning ScriptBlock, which will be a parameter for most.
As you see there is a lot of information available ;-)