A few PowerShell tips – Part 1 – The one about help.

Long time ago I watched really interesting training about PowerShell 3.0, it can be found here:

https://mva.microsoft.com/en-US/training-courses/getting-started-with-powershell-3-0-jump-start-8276?l=5Rb7mQWy_5704984382

I noticed that sometimes I forget things that were mentioned in there, and lots of my colleagues is not even ware about some of the PowerShell abilities.

It is for sure not about remembering all the stuff, it is about knowing where to find stuff, so do not think there is something wrong with you if you do not remember something:

PowerShell_GetHelp15

No you are not! And do not blame yourself every time you forgot that one switch for cmdlet:

PowerShell_GetHelp16

So, today’s post is about Get-Help,as it is always good to have crucial / useful information written down – just like Homer Simpson has:

PowerShell_GetHelp7

Get-Help / Help / Man – differences

 

Get-Help is giving you help at one shot, while Help / Man works like “more” or “less” in Linux, it gives you help “page by page”.

PowerShell_GetHelp1

Get-Help switches:

 

-Examples: Gives you only examples for cmdlet:

PowerShell_GetHelp2

-Detailed: Returns full information about cmdlet including examples.

-Full: Gives actually very similar output to what -Full returns + detailed description of parameters, telling if a particular parameter is accepting pipeline data as input:

PowerShell_GetHelp3
In the above example -ComputerName is accepting input by property name, what does this mean for us? Well, having that we can call his cmdlet like that:

Get-ADComputer -Filter * | Get-Service

If “Accept pipeline input?” on -ComputerName would be set to “false”, we won’t be able to run such command. We would need to use other trick 🙂 but will write about that in second part.

-Online: Redirects us to the online version of help.

-ShowWindow: Shows a help information in a very nice searchable, zoomable format 🙂

PowerShell_GetHelp4

Searching for help

 

PowerShell_GetHelp9

If you do not remember exact name of the cmdlet you are looking for, you can try use the wildcard (or star / asterisks) like in this example:

Get-help *service* will return:

PowerShell_GetHelp5

Get-Help about* will give us decent list of documents explaining the usage of particular cmdlet:

PowerShell_GetHelp12

We can also combine it with -ShowWindow switch.

Get-Help about_aliases -ShowWindow will return:

PowerShell_GetHelp6

Get-help for category

 

It is possible to get help for particular category of cmdlets. To check what are the options you can try to run Get-Help with imaginary -Category parameter value, like “asd”, after running this command I was told what available options were:

“Alias, Cmdlet, Provider, General, FAQ, Glossary, HelpFile, ScriptCommand, Function, Filter, ExternalScript, All, DefaultHelp, Workflow”

Get-Help -Category asd returns:

PowerShell_GetHelp11

What is really useful and worth checking out are “about” documents about operators:

Get-Help *operators*

PowerShell_GetHelp13

Understanding brackets in help

 

Now a few words about help content itself, so information gathered from it can be actually really useful.

PowerShell_GetHelp14

Brackets “[ ]” around parameter mean it is main parameter.

PowerShell_GetHelp17

So if we trigger a cmdlet without clearly given attribute but with only a value, that value will be treated as a value for that particular parameter, so in above example “[-Name]” is the main parameter for Get-Service cmdlet.

Also, brackets in “String[]” means that parameter is accepting multiple values – comma separated. Using that both information this is how we can run this command:

Get-Service bits, w32time

PowerShell_GetHelp18

Saving / exporting help locally

 

It is possible to save help files locally, and later move it to the host that is placed, for example, in perimeter (DMZ) network.

Save-Help \\<PATH>

Updating help

 

To update help files on a local computer we use:

Update-Help

To update help using previously saved help file we use:

Update-Help -source \\<PATH>

Advertisements