Load
a
S nap
I n
Load
a
S nap
i n
f or
a dded
f unctionality,
s upressing
e rror
i nfo
i f
t he
s nap
i n
i s
a lready
l oaded.
Add-‐PSSnapin
m icrosoft.sharepoint.powershell
-‐ ErrorAction
S ilentlyContinue
Working
W ith
S hortened
c ommands
( Aliases)
Use
G et-‐Alias
t o
l ist
o ut
a ll
c ommands
w ith
s hortened
a lternatives
Get-Alias
Find
t he
l ong
f orm
o f
a
c ommand
f rom
i ts
a lias:
Get-Alias –name dir
Find
a ll
a liases
o f
a
f orm
o f
a
c ommand
f rom
i ts
a lias:
Get-Alias –Definition “Get-ChildItem”
Refining
o utput
Where-‐Object
( Where)
Sort-‐Object
( Sort)
Where
i s
u sed
t o
l imit
t he
o utput
o f
a
c ommand
Limit
w hich
f ields
a re
r eturned
Command
|
W here
{ $_.ParameterName
– like
“ value”}
Long
F orm:
$a = dir |Where {$_.PSIsContainer –eq $true}
Dir | Sort-Object Name
Short
F orm:
Dir | Sort Name, Length
Select-‐Object
( Select)
Listing
D etails
Limit
w hich
f ields
a re
r eturned
Sometimes
t here
i s
m ore
t han
i s
s hown
b y
d efault
Dir | Select Name, Length
Format-‐List
o utputs
m ore
f ields,
i n
a
l ist
f ormat
Limit
h ow
m any
r esults
a re
r eturned
Dir | Format-list
Dir | Select –First 3
Dir | fl
Chaining
M ultiple
C ommands
Multiple
c ommands
a nd
r efiners
c an
b e
u sed
t o
g et
j ust
t he
r ight
o utput:
Dir | where {$_.PSIsContainer –eq $true} | Sort name | Select –first 3
Learning
a bout
a
r esult
b y
u sing
w here,
t he
d ot
( .)
a nd
t ab
Some
c ommands
r eturn
c omplex
r esults
t hat
c an
b e
f urther
b roken
d own.
It
i s
o ften
h elpful
t o
n arrow
d own
t he
r esults
t o
j ust
o ne
i tem,
a nd
a ssign
t hat
o ne
r esult
t o
a
v ariable
s o
that
y ou
c an
i nspect
i ts
p roperties.
$d = Dir #returns too much
$d = Dir | select –first #better, returns one entry
At
t his
p oint
y ou
c an
t ype
$ d.
a nd
h it
t he
t ab
k ey
r epeatedly
t o
s ee
t he
d ifferent
p roperties.
$d.(tab) #starts to list the properties such as $d.name, $d.fullname
Another
e xample,
u sing
w here
t o
p ick
t he
s pecific
r esult
t o
i nspect
$d = Dir | Where {$_.name –eq “Windows”}