PowerShell Cheat Sheet V2.00 PDF
PowerShell Cheat Sheet V2.00 PDF
Refining
output
Where-‐Object
(Where)
Sort-‐Object
(Sort)
Where
is
used
to
limit
the
output
of
a
command
Limit
which
fields
are
returned
Command
|
Where
{$_.ParameterName
–like
“value”}
Long
Form:
$a = dir |Where {$_.PSIsContainer –eq $true} Dir | Sort-Object Name
Short
Form:
Dir | Sort Name, Length
Select-‐Object
(Select)
Limit
which
fields
are
returned
Listing
Details
Dir | Select Name, Length Sometimes
there
is
more
than
is
shown
by
default
Limit
how
many
results
are
returned
Format-‐List
outputs
more
fields,
in
a
list
format
Dir | Select –First 3 Dir | Format-list
Dir | fl
Learning
about
a
result
by
using
where,
the
dot
(.)
and
tab
Some
commands
return
complex
results
that
can
be
further
broken
down.
It
is
often
helpful
to
narrow
down
the
results
to
just
one
item,
and
assign
that
one
result
to
a
variable
so
that
you
can
inspect
its
properties.
$d = Dir #returns too much
$d = Dir | select –first #better, returns one entry
At
this
point
you
can
type
$d.
and
hit
the
tab
key
repeatedly
to
see
the
different
properties.
$d.(tab) #starts to list the properties such as $d.name, $d.fullname
Another
example,
using
where
to
pick
the
specific
result
to
inspect
$d = Dir | Where {$_.name –eq “Windows”}