Presentation and demo material - An Introduction to PowerShell

Thank you to those of you who attended the Powershell session at the December 2007 Premier Briefing event in Melbourne Australia. I hope you found the session informative. I have attached the presentation slides and the demo script I used on the day. It is actually an updated version of the presentation I delivered at TechEd 2007. I ran the demo script using Jeffrey Snover's "start-demo" script which you can find here https://blogs.msdn.com/powershell/archive/2007/06/03/new-and-improved-start-demo.aspx, although it's not needed if you just want to see the commands that we ran on the day. Please contact me if you would like more information.

Thanks.
Chris.

 # Demo #1 - Online HELP #
##########################
help
help help
help -full help
dir
pwd
ipconfig /all
get-command *process*
get-process
get-process | where { $_.name -like "*ss" }
get-process|gm
get-service
get-service | where { $_.status -eq "Stopped" }
# Demo #2 - Getting available commands (cmd #7) #
#################################################
help get-command
get-command help
dir function:help
type function:help
man
type function:man
get-command
get-command -type function
(get-command).count
(get-command -type function).count
# get-command -type all
(get-command -type all).count
(get-command *).count
# Demo #3 - Common Paramemters  (cmd #23) #
###########################################
get-content profile.ps1
get-content profile.ps1 ; dir
get-content profile.notexist ; dir
get-content profile.notexist -erroraction continue ; dir
get-content profile.notexist -erroraction stop ; dir
get-content profile.notexist -erroraction inquire ; dir
get-content profile.notexist -erroraction silentlycontinue ; dir
$error.gettype()
$error.count
$error[0]
get-content profile.notexist -errorvariable myerrvar
$error
$myerrvar
get-process -name "*ss" -outvariable myoutvar
$myoutvar
stop-process -name "*ss" -whatif
stop-process -name "*ss" -confirm
# Demo #4 - PS Providers  (cmd #43) #
#####################################
get-psdrive
help *provider*
get-psprovider
new-psdrive -name psdocs -psprovider filesystem -root C:\windows\system32\windowspowershell\v1.0\documents\en-us
cd $home
dir
cd psdocs:
dir
cd $home
# Exploring the registry
cd hklm:\
dir
cd hardware\description\system\centralprocessor
dir
$p = get-childitem
$p
$p|gm
$p[0].getvaluenames()
$p[0].getvalue("processornamestring")
foreach ( $name in $p[0].getvaluenames() ) { write-host "$name = " + $p[0].getvalue($name) }
# Demo #5 - Results as Objects  (cmd #67) #
###########################################
$s = "a,b,c,def   "
$s
$s.gettype()
$s.split(",")
$s.split(",")|where { $_ -like "*[d-f]" }
$s.length
$s = $s.trim()
$s.length
calc
gps -name calc
$calc = gps -name calc
$calc|gm
$calc|select *
# Exit the Calc program
gps -name calc
$calc |select *
# Demo #6 - COM Objects  (cmd #77) #
####################################
$ie = new-object -com internetexplorer.application
$ie|gm
$ie|select *
$ie.visible=$true
$ie.navigate2("www.microsoft.com/powershell")
$voice = new-object -com sapi.spvoice
$voice.speak("Powershell is so good, it speaks for itself.")
# Demo #7 - Debugging    (cmd #83) #
####################################
set-psdebug -trace 2
set-psdebug -trace 0
set-psdebug -trace 0
$host
$host|gm
write-host "CONDITION=true Entering Nested prompt. Type 'exit' to return"
$host.enternestedprompt()
# Demo #8 - WMI Objects  (cmd #83) #
####################################
get-wmiobject win32_bios
get-wmiobject win32_bios|gm
man gwmi
gwmi -list
gwmi -list | where { $_.name -like "*eventlog*" }
gwmi win32_eventlogfile
get-eventlog -list
get-eventlog -newest 5 system
# Demo #9 - ADSI Objects  (cmd #91) #
#####################################
[adsi]""

POWERSHELL-Intro-ChrisGreen-Premier.pdf