Skip to content

Notes: Cmdlets and Members

echadbourne edited this page Sep 5, 2024 · 1 revision

Cmdlets

Native powershell coammnds, not stand alone executables. Cmdlets perform an action and typically return a Microsoft .NET object

Powershell uses a Verb-Noun name pair to name cmdlets

The verb identifies the action that the cmdlet performs, and the noun identifies the resource on which the cmdlet performs its action

  • Get-Help
  • Get-Process
  • Get-Service

Properties

Members of the class that contain data, Different types of objects have different properties

ScriptProperty - A property defined by script langiage whose value is the output of a script

AliasProperty - Defines a new name for an existing property

NoteProperty - Defines a property that has a static value

Get-Process displays only 7 properties. To see the properties you want, you can use "select"

  • You can Select all ("Select *")

Get-Process | select Name, StartTime

Methods

A set of instructions that specify an action you can perform on the object returned by the cmdlet

Kill method for a Process Object returned by Get Process cmdlet, terminates the process

$notepad = Get-Process notepad

$notepad.Kill()

image

Where-Object

Powershell includes the $PSItem variable and its alias, $_, as automatic variables in script blocks that process the current object, such as in the pipeline

The $_ automatic variable represents each object that's passed to the Where-Object cmdlet. The first command uses the script block format, the second command uses the comparison statement format

image

image

Custom Attributes for Output

image

Powershell Switches

Powershell has commands for controlling the flow of execution within your scripts. One of those statements is the switch statement

Help

help *service* will give you a list of items on "help" that contains the word service

image

Clone this wiki locally