cn1266 network scripting v1 2
Download
Skip this Video
Download Presentation
CN1266 Network Scripting V1.2

Loading in 2 Seconds...

play fullscreen
1 / 34

CN1266 Network Scripting V1.2 - PowerPoint PPT Presentation


  • 48 Views
  • Uploaded on

CN1266 Network Scripting V1.2. Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+. Agenda. Chapter 4: Shelling Out Commands and Scripts Chapter 5: When Dollars Turn into Variables Chapter 6: A Bit of Logic to Save the Day Flowchart and Pseudo code

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' CN1266 Network Scripting V1.2' - prema


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
cn1266 network scripting v1 2

CN1266 Network Scripting V1.2

Kemtis Kunanuraksapong

MSIS with Distinction

MCTS, MCDST, MCP, A+

agenda
Agenda
  • Chapter 4: Shelling Out Commands and Scripts
  • Chapter 5: When Dollars Turn into Variables
  • Chapter 6: A Bit of Logic to Save the Day
  • Flowchart and Pseudo code
  • Chapter 26: The Ten Most Important Cmdlets (1,7)
  • Chapter 27: Ten Common PowerShell Mistakes (5,6,7)
cmdlets
CMDLets
  • To see the list of the commands
  • Get-Command
  • Get-Command | More
  • Pipe (|) is used to pass the output of any command to another. See Chapter 7
cmdlets cont
CMDLets (Cont.)
  • Get-Help
  • Get-Help Get-Alias
  • Get-Help Get-Alias –detailed
    • More information
  • Get-Help Get-Alias -full
    • More technical information
  • Try
    • Get-help get-service
cmdlets cont1
CMDLets (Cont.)
  • Try these:
    • Get-service –name eventlog, spooler
    • Get-service eventlog, spooler
one shell to rule them all
One shell to rule them all
  • Command Shell – dir, md, rd
  • Windows script host
    • VBScript (.vbs) or JavaScript (.js)
    • Use CScript.exe or WScript.exe
variables
Variables
  • What is variable?
    • Can contain character(s), symbol(s), and special character(s)
    • $MyVar
    • $A6
    • ${Var with Space}
    • ${[email protected]}
  • Camel case notation - $ThisIsAnExample
  • Get-Help Set-Variable
data types
Data Types
  • Kinds of values
  • Variants – can take on any data type
  • Primitive values – basic data types such as
    • Boolean
    • Char
    • Date
    • Integer
    • See more on Page 63
working with data types
Working with data types
  • Try these code:
    • $a = 2
    • $b = 3
    • $c =$a+$b
    • Write-output $c
  • Try put “2” in stead of 2
    • $a = “2”
    • $b=“3”
working with data types 2
Working with data types (2)
  • By adding double quotation mark, it explicitly defines the variable as string or text
  • Plus sign becomes to concatenate the string instead of addition
why should we explicitly define
Why should we explicitly define
  • Unexpected values
    • To reduce the chance of type mismatch
  • Clarity
  • Improved performance
    • PSH knows right away without checking the type
why should we explicitly define 2
Why should we explicitly define (2)
  • Try this:
    • [int]$IntOnly = 100
    • $Sum = 2 + $IntOnly
    • Write-output $sum
    • $IntOnly = “PowerShell Rules!”
    • Write-output $IntOnly +” Yes, it does”
  • $IntOnly.GetType().Name
why should we explicitly define 3
Why should we explicitly define (3)
  • Table 5-1 on Page 67 shows the shortcut of data type for explicitly defined variable
  • Casting – a process or way to convert data type
why should we explicitly define 4
Why should we explicitly define (4)
  • Try these:
    • $MyString = “ Windows PowerShell “
    • $MyDouble = 2.0
    • $OutString = $MyString + $MyDouble
    • Write-output $OutString
  • Try these:
    • $OutString = $MyDouble + $MyString
why should we explicitly define 5
Why should we explicitly define (5)
  • Try these:
    • $OutString = [string]$MyDouble + $MyString
  • OR
    • $OutString = ($MyDouble –as [string]) + $MyString
constant and read only var
Constant and Read-Only Var.
  • You have to use
    • Set-Variable [-Option {None | ReadOnly | Constant | Private | AllScope}]
    • Remove-Variable
  • Try:
    • Set-Variable PI 3.141 –option constant
    • Set-Variable School “Remington” –option Readonly
    • Write-output “Pi’s value is ” + $PI +

“ This code is run at “ + $School

automatic variables
Automatic Variables
  • What is automatic variables?
    • Pre-assigned by PSH
    • See Table 5-2 on Page 72 - 73
working with objects
Working with Objects
  • Properties?
  • Method?
  • Try code on Page 75 and 76
star trek quiz game
Star Trek Quiz Game
  • See Handout
  • Challenge: Modify the StarTrek Quiz so that it displays the correct answer for any question that the player misses
a logic primer
A Logic Primer
  • Automatic variables : $true, $false
  • And
  • Or
  • Exclusive (XOR)
  • Not
  • Try code on page 79
order of precedence
Order of Precedence
  • ( )
  • Negate (Not)
  • And
  • Or
  • XOR
logical operator
Logical Operator
  • See table 6-5 on Page 79 - 80
  • Try the code on page80
if else
IF / Else
  • Remember the flow chart?
    • $Name = “Kemtis”
    • If ($name –eq “Kemtis”){

Write-host “Hello Kemtis!”

    • } else {

Write-host “Hello sir”

    • }
  • OR
    • If ($name –eq “Kemtis”){Write-host “Hello Kemtis!” }
if elseif else
IF / ElseIf/Else
  • If/Elseif/Else
    • $grade = 60
    • If ($grade –ge 90){ Write-host “A”
    • }Else{ If ($grade –ge 80) { Write-host “B”}
    • Else{If ($grade -lt 80){Write-host “F”}
    • }}
if elseif else 3
IF / ElseIf/Else (3)
  • If/Elseif/Else
    • #Grade V2.0
    • $grade = 60
    • If ($grade –ge 90){ Write-host “A”
    • }ElseIf ($grade –ge 80) { Write-host “B”
    • }ElseIf ($grade -lt 80){Write-host “F”}
switch statement
Switch Statement
  • $size = “M”
  • Switch($size){
  • “S” {Write-host “Small”}
  • “M” {Write-host “Medium”}
  • “L” {Write-host “Large”}
  • default {Write-host “Unknown”}
  • }
looping
Looping
  • For loop
  • ForEach loop
  • While loop
  • Do While loop
  • Do Until loop
  • Infinite loop
for loop
For Loop
  • For ($i =1; $i –le 5; $i++)
  • {
  • Write-Host $i
  • }
foreach loop
ForEach Loop
  • Foreach ($i in Get-Alias)
  • {
  • Write-Host $i.name
  • }
while loop
While Loop
  • $objRandom = New-Object Random
  • $val = $objRandom.Next(1,10)
  • While ($val –ne 7){
  • Write-host (“You got a “ + $val + “…”)
  • $val = $objRandom.Next(1,10)
  • }
  • Write-host “Congrat! You got a 7”
do while loop
Do While Loop
  • $objRandom = New-Object Random
  • do {
  • $val = $objRandom.Next(1,10)
  • Write-host (“You got a “ + $val + “…”)
  • } While ($val –ne 7)
  • Write-host “Congrat! You got a 7”
do until loop
Do Until Loop
  • $objRandom = New-Object Random
  • do {
  • $val = $objRandom.Next(1,10)
  • Write-host (“You got a “ + $val + “…”)
  • } Until ($val –eq 7)
  • Write-host “Congrat! You got a 7”
infinite loop
Infinite Loop
  • $objRandom = New-Object Random
  • $val = $objRandom.Next(1,10)
  • While ($val –ne 10){
  • Write-host (“You got a “ + $val + “…”)
  • $val = $objRandom.Next(1,10)
  • }
  • Write-host “Congrat! You got a 11”
guess my number game
Guess My Number Game
  • See handout
  • Homework:
    • Make the game more intuitive by adding additional instructions and guidance. (IE. You are getting very close)
    • Modify the game to allow the player to quit at any time, instead of just at the end of the current round of play.
ad