Day 1

Terminology

get-eventlog -newest 10 

Parameter (-newest)

Argument (10 )

 

get-help about_parameter

  Accepts Multiple Values?

get-help Get-WmiObject -full | more

-computerName <string[]>

this means this will except a string array

 

 

Get-help

get-help Get-EventLog -full | more

[]square brackets for optional

<>angeled for required

[-LogName] <string>

-Logname parameter is optional but the argument for it is required ( this works because it is a positional parameter if you scroll down in the help details you can see it is postion 1 for -Logname (this means that the first unbound parrameter will be used for this

Get-EventLog -newest 10 application

-newest 10 is a parameter and its argument and application is the first positional paramenter

[-ComputerName <string[]>]

this is an optional parameter but if you use it it has a required argument

Get-Help about

Get-Help about_operator

  Built in variables

$PSHOME

$_

$PWD

 

Objects

 

HashTables

$myhash= @{}

$myhash.gettype()

$myhash.FirstName = "Kevin"

$myhash.LastName = "Curran"

$myhash.FirstName + " " + $myhash.LastName

 

use a hash table to display the output we want

 

@{Label="Handles";Expression={$_.HandleCount}

Get-Process | Where-Object {$_.handlecount -gt 200} | Sort-Object -Descending -Property handlecount | Format-Table id,processname,@{Label="Handles";Expression={$_.HandleCount}} -autosize

 

$ary = "Hello", "World!"

 join dilimited by space (` is used to escape the space)

 

[string]::join("` ",$ary)

join dilimited by comma

[string]::join(",",$ary)

 

$string= "Hello World!"

$mat = [regex]::match($string,"o\sW")

$mat.Value

 

Common Parameters

Page 13 of Windows Powershell step by step book 

Whatif and Confirm

stop-process -name notepad* -whatif

stop-process -name notepad* -confirm