- Cmdlets follow a standard "Verb-Noun" naming convention.
- Get help for a particular command:
- get-help [cmdlet]
- To filter most any results you can:
- use where-object and the property of the object needs to be referenced as $_.[propertyname]
- Get all PowerShell commands:
- get-command | where-object { $_.commandtype -eq "cmdlet"}
- F7 shows the history buffer
- Useful parameters most all cmdlets have:
- -whatif – Cmdlet is not actually executed, provides information about “what would happen” if executed.
- -confirm - Prompt user before executing cmdlet.
- -Verbose - Provides more detail.
- -debug - Provides debugging information.
- -ErrorAction - Instructs cmdlet to perform an action when errors occur. Such as: continue, stop, silently continue, and inquire.
- -ErrorVariable - Use a specific variable to hold error information. This is in addition to the standard $error variable.
- -OutVariable - Variable used to hold output information.
- -OutBuffer - Hold a certain number of objects before calling the next cmdlet in the pipeline.
- To make a comment in PowerShell use #.
- PowerShell allows you to work with more than just the file system.
- To get a list of providers:
- Get-PSProvider
- To get a list of drives to connect to:
- Get-PSDrive
- To connect to that drive:
- Set-Location D:\
- Common Special Variable Examples:
- $_ – Contains the current pipeline object, used in script blocks, filters, and the where statement.
- $Args – Contains an array of the parameters passed to a function.
- $Error – Contains objects for which an error occurred while being processed in a cmdlet.
- $Home – Specifies the user’s home directory.
- $PsHome – The directory where the Windows PowerShell is installed.
- Get-Help about_automatic_variables – To see them all
- How to create an array (hash value work the same with an equal sign):
- $arrayVariable = @(List of comma separated values)
- Conditional Logic:
- -eq - Equal to
- -lt - Less than
- -gt - Greater than
- -ge - Greater than or Eqaul to
- -le - Less than or equal to
- -ne - Not equal to
- The switch statement doesn't use the word case.
- To denote the end of a line or command use a semicolon, however this is only required if you're trying to do multiple commands on one line (to my knowledge).
- You can create your own PowerShell functions.
- Use the keyword "Function".
- Final thing is building your code library. Since you can create functions for things you commonly do you might want to just create some files to manage these functions and then reference them from the current script you are creating. Here's a good explanation of how to use and reference functions.
Most of this information was compiled from the PowerShell Pro website. However, I took things that I found important, added my own things that I already knew to create this post.