Getting help

A Word on Fonts

Before we dive into the typing anything into the PowerShell console, a quick word on fonts and colours. There are a number of “special characters” that are used a lot in PowerShell and especially as we move into scripting later. It is important that you can identify these in your commands and code.

  • Backtick `
  • Apostrophe
  • Quotes or double apostrophes
  • Brackets ( )
  • Braces or Curly Brackets { }
  • Greater than and less than symbols < >
  • A pipe symbol | This is not a lowercase l (L) nor is it an upper case I (i). You can see the difference in this code excerpt because the font makes it clearer, it’s not at all clear in the post text.
| l I

Pay heed this may catch you out when reading the code from others.

Colour

Yes I spelt that correctly.

Why mention colour in a tutorial about PowerShell? Well because i’ve seen some awful colour schemes and you need to think about what may happen… this is just one example… please test any new schemes you configure, don’t make your life harder than necessary

PowerShell console with yellow text on light grey background

Updating Help

The first thing to do is ensure that your help files have been downloaded and are up to date. Without doing so you will get an error when you try to ask for help.

Open PowerShell and run this command, when it completes you will find a plethora of txt based files in C:\Windows\System32\WindowsPowerShell\v1.0\en-US

Update-Help

Finding Commands

One of the challenges with PowerShell is finding a command that does what you require. Fortunately they have provided us with a pretty good starting point in the form of Get-Command

Get-Command will get any commands in the specified filter that are available on the local machine. Modules need to be installed but not imported.

NOTE: This won’t show commands from Exchange unless PowerShell is connected to either Exchange on-premise or Exchange Online

Return all commands with the text ‘rest’ in them

Get-Command *-*rest*

Return only the Get- commands with text ‘rest’ in them

Get-Command get-*rest*

Return any commands with a parameter called ‘computername’

Get-Command -parametername computername

Getting Help

Now you can find the command you want, how do you use it, what is required and what is optional?

You can use the Get-Help cmdlet to assist finding parameters and information about them

Get-Help <cmdlet>

Here is an example using the cmdlet Get-Eventlog

When you get the response, check the syntax.

SYNTAX    Get-EventLog [-LogName] <string> [[-InstanceId] <long[]>]

In this example, the parameter [-LogName] and type <string>are not completely enclosed in square brackets [] – this means that they are mandatory, you must supply a string for the log name. However [[InstanceID] <long[]>] are entirely enclosed in square brackets which indicates it is optional.

Get-EventLog -LogName security -InstanceID 4624

You can also apply this mandatory/optional concept to the parameter names – both [-LogName] and [-InstanceID] are enclosed in square brackets. This indicates that they are optional allowing you supply the values without the parameter name like this

Get-EventLog security 4624

TL;DR – when you look at the help file, items enclosed in square brackets [ ] are optional.

-ShowWindow

You can open the help result in a new window by using the -ShowWindow parameter

Get-Help Get-Eventlog -ShowWindow

Show-Command

If you want to create a command by filling in a form or just see see all available parameters try this

Show-Command <cmdlet>

This will open a dialogue box like this

You can complete the boxes you need to and click copy, this will put the formatted command into the clipboard so you can paste it elsewhere and see what it looks like.

You can also run it directly from this box by clicking run.

Version

Some commands are only available in certain versions of PS, you can find your versions by typing this in a PowerShell console

$PSVersionTable

Transcript

Recording a transcript of everything you type and everything that is returned can be useful for troubleshooting or reverting your changes

Start-Transcript <filename>

end the transcript recording.

End-Transcript <filename>

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.