PowerShell Tutorial – CmdLets

Executing the Get-Command cmdlet will provide a full listing of all the cmdlets available in PowerShell (as well as all the Aliases, Functions etc):

PowerShell Tutorial

Executing Get-Help for a cmdlet will provide details on how to use the cmdlet, for example say if you wanted to see the usage for the Add-Computer cmdlet.

PowerShell Tutorial

The Get-Help cmdlet can even provide examples of cmdlets working:

PowerShell Tutorial

Aliases

Each PowerShell cmdlet associates with an alias. You can use the alias instead of cmdlet full name. Execute Get-Alias for a full listing of all the Aliases in PowerShell (the Definition in the listing is the original Cmdlet name).

PowerShell Tutorial

If you think cmdlet full name is a bit difficult, you can use short names (ie aliases) but note that this reduces the readability of the script. I prefer to use full names in scripts and aliases for ad-hoc queries.

Scripts

PowerShell scripts are text files with the extension of “.ps1”. You can write PowerShell scripts by using cmdlets and save themfor future use. Commonly used tasks are good candidates for scripts.  By default PowerShell prevents the execution of any script, due to the execution policy of the PowerShell. You can see the current execution policy in PowerShell  using the  Get-ExecutionPolicy cmdlet.

There are four levels of execution policies.

1. Restricted – Default setting of PowerShell. No scripts can run

2. AllSigned- Scripts should have the trusted digital signature

3. RemoteSigned

4. Unrestricted- Any script can run.

You can change the execution policy using the Set-ExecutionPolicy cmdlet.  PowerShell needs to be “Run as Administrator” in order to set execution policy.

PowerShell Tutorial

One thought on “PowerShell Tutorial – CmdLets

  1. Pingback: PowerShell for Sharepoint – Cmdlets | Windows Server Help

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>