Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Getting Started

All of Powershell's commands follow a Verb-Object pattern.

Powershell is object-oriented, thus every object has methods and properties.

Common Commands

Manage Processes

...

Powershell has a great built-in help system which is incredibly useful for gaining info on commands or Powershell properties. Look at the below command:

"Get-Help Start-Process"

This will bring up some basic information about the command such as Syntax, Description, and Related Links, BUT it can do so much more. You can control how much detail the "Help" system gives you by using certain switches such as "-Detailed", "-Full", and "-Examples". I recommend the "-ShowWindow" switch which will give you all the available details in a separate window, which is great for keeping the console window clean:

"Get-Help Start-Process -ShowWindow"

"Help" can also be used to search for commands or modules of interest and it accepts wildcards.

"Get-Help *process*" will bring all commands that have "process" anywhere in the name. Additionally you can use only one asterisk, "*process" or "process*", if you want to search for commands that have "process" in either the front or the back.

Variables

Powershell will let you save and use variables inside both scripts and console windows. 

$Var = ...

This function makes invoking methods much simpler. Here's a common one:

$Bitness = Get-wmiobject win32_operatingsystem

$Bitness.OSarchitecture

The former line grabs the OS object and stores it into the variable. This means one can use the variable to invoke all the methods and properties assigned to the object.

It takes two lines but is easier to use and read than the alternative:

(Get-wmiobject win32_operatingsystem).OSarchitecture

The latter would require entering the entire line to access the property. If you only need the one property then

$Bitness = (Get-wmiobject win32_operatingsystem).OSarchitecture

is better to use.

Pipeline