Versions Compared

Key

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

...

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 as it stores the string found in "OSarchitecture" instead of storing the whole object.

...

Running the above line from an admin level command line will run powershell as admin, then from the powershell instance, it will run whatever .ps1 file you give it. Additionally, it won't alter the default policies set for the machine or user.

Invoking commands

Again, PowerShell is object-oriented, and every object has methods and properties. In order to view an object's methods and properties, we use the Get-Member command.

Get-Process -Name Chrome | Get-Member

shows us all the methods and properties associated with the Chrome browser. This syntax can be used with every object and command (to the best of my knowledge). Using the above syntax can get write heavy so I suggest using Get-Member's shortcut, gm.

Get-Process -Name Chrome | gm

will function the same as the former line. Once you have a property or method in mind, you can then invoke it.

If it's a method then you must use parenthesis at the end like such:

(Get-Process -Name Chrome).Start()

If it's a property then you do not need the parenthesis:

(Get-Process -Name Chrome).SessionId

If you store an object into a variable, then invoking commands becomes a bit simpler:

$Process.Start()
$Process.SessionId

External Resources

List of  Aliases

Microsoft's articles about Powershell and its modules. The commands can be found under "References" and their respective modules. Microsoft.Powershell.Core and Microsoft.PowerShell.Utility are good starts.

Several instruction videos covering several Powershell features. Scroll through contents to view specific topics. May require a @live.com or @hotmail.com account to view entire series.