kemtis kunanuraksapong msis with distinction mcts, mcdst, mcp, a+
TRANSCRIPT
![Page 1: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/1.jpg)
CN1266 NETWORK SCRIPTING
Kemtis KunanuraksapongMSIS with DistinctionMCTS, MCDST, MCP, A+
![Page 2: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/2.jpg)
AGENDA
Chapter 7: Working on a Pipeline Chapter 9: Bringing Strings into the
Limelight
![Page 3: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/3.jpg)
WHAT IS PIPING
When you take the output of one command and direct it to the input of another command
Try this on command prompt Ipconfig | find “ipv4 address” Dir c:\windows\system32 | find “.exe”
![Page 4: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/4.jpg)
STRINGING COMMANDS TOGETHER
Try this: Get-childitem c:\windows\system32 |
format-table Get-childitem c:\windows\system32 |
format-list Get-childitem c:\windows\system32 |
format-wide
![Page 5: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/5.jpg)
STRINGING COMMANDS TOGETHER (2) Cmdlets use out-default as a default
format to shows the output All object are returned to the command as
a stream of data
![Page 6: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/6.jpg)
GETTING THE RIGHT OUTPUT
Get-process | format-table Get-process | format-table –property id, name Get-process | format-table –property name, id Get-process | where-object {$_.Id –gt 1000} | format-
table –property name, cpu, id $_ refers to the current object in the pipe-line
Get-process | where-object {$_.Id –gt 1000} | select-object name, cpu, id | sort-object CPU, ID
![Page 7: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/7.jpg)
CHAPTER 9 BRINGING STRINGS INTO THE LIMELIGHT
![Page 8: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/8.jpg)
WHAT IS STRING?
A technical name for text A consecutive sequence of characters Empty VS Null Strings
Empty string – a string with zero length Null string – undefined string (no value, no
length, nothing)
![Page 9: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/9.jpg)
LITERAL STRINGS
A literal string is enclosed by double quotes “this is the a literal string” + “… so the story continues…”
Here-Strings $RegularString = “First Line of string`n” + “Second line `n” + “Third line” Write-host $RegularString
![Page 10: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/10.jpg)
LITERAL STRINGS (2)
Here-Strings $MyHereString = @“ First Line of string Second line Third line ”@ Write-host $MyHereString
You also can use quotation in here-string
![Page 11: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/11.jpg)
COMBINING STRINGS
+ (Concatenation) – to combine string together See code in Page 120
You can implicitly or explicitly convert the data type into string See codes in Page 121
![Page 12: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/12.jpg)
SPLITTING STRINGS
Method split() is used to spilt the string into array of strings $str = “this book is good!” $str.split()
![Page 13: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/13.jpg)
SPLITTING STRINGS (2)
$myIP = “192.168.10.100” $ipArr = $myIP.split(“.”) Write-Host (“Number of elements in ipArr”
+ $ipArr.length) Write-Host (“First octet: “ + $ipArr[0]) Write-Host (“Second octet: “ + $ipArr[1]) Write-Host (“Third octet: “ + $ipArr[2]) Write-Host (“Fourth octet: “ + $ipArr[3])
![Page 14: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/14.jpg)
SPLITTING STRINGS (3)
$myIP = “192.168,10;100” $ipArr = $myIP.split(“.,;”) Write-Host (“Number of elements in ipArr”
+ $ipArr.length) Write-Host (“First octet: “ + $ipArr[0]) Write-Host (“Second octet: “ + $ipArr[1]) Write-Host (“Third octet: “ + $ipArr[2]) Write-Host (“Fourth octet: “ + $ipArr[3])
![Page 15: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/15.jpg)
SNIPPING OFF A PIECE OF A STRING
Method substring() $name = “Steve Seguis” $part1 = $name.substring(0,3) $part2 = $name.substring($name.length-
4,4) Write-Host ($part1 + $part2)
![Page 16: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/16.jpg)
![Page 17: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/17.jpg)
STRING SUBSTITUTIONS
$str = “Steve is EVIL!!!” $newstr = $str.replace(“EVIL”,”Good~”) Write-Host $newstr
![Page 18: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/18.jpg)
STRING POSITIONS
Method IndexOf() is used to find the specific character in the string $email = “[email protected]” $atpos = $email.IndexOf(“@”) $user = $email.substring(0, $atpos) $domain = $email.substring($atpos+1,
$email.length-($atpos+1)) Write-Host (“Username: “ + $user) Write-Host (“Domain: “ + $domain)
![Page 19: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/19.jpg)
STRING POSITIONS (2)
$email = “My_invalid_email_address” If ($email.IndexOf(“@”) –lt 0){
Write-Host “Invalid email address!” }else{
Write-Host “Valid email address!” }
![Page 20: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/20.jpg)
CASE OF STRINGS
Upper case ToUpper() method
Lower case ToLower() method
![Page 21: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/21.jpg)
REGULAR EXPRESSION
A search pattern [RegEx]::IsMatch(“This book is really
interesting.”,”book”) [RegEx]::IsMatch(“I have 2 siblings”,”[0-
9]”) *NOTE* It is case sensitive
![Page 22: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/22.jpg)
REGULAR EXPRESSION (2)
You can use escape string (\) if you want to search for special character on page 129 [RegEx]::IsMatch(“Visit us at
dummies.com”,”dummies\.com”) . (dot) is a single-character wildcard
[RegEx]::IsMatch(“bell”,”.ell”)
![Page 23: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/23.jpg)
REGULAR EXPRESSION (3)
$username = “testuser1” [RegEx]::IsMatch($username,
“testuser[0-9]”)
If you want the name to end with either ‘a’ or ‘e’ $name = “Anna” [RegEx]::IsMatch($name,”Ann[ae]”)
![Page 24: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/24.jpg)
REGULAR EXPRESSION (4)
If you want to exclude character from a match, you can negate a character set by prefixing it with the caret (^) [RegEx]::IsMatch(“food”,”[^fh]ood”)
See Table 9-1 on Page 131 for more information
![Page 25: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/25.jpg)
DEFINE OPTIONAL
Question mask (?) indicates that the preceding character can exist zero times or one time [RegEx]::IsMatch(“favorite”,”favou?rite”) [RegEx]::IsMatch(“favourite”,”favou?rite”) [RegEx]::IsMatch(“Monday”,”Mon(day)?”)
![Page 26: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/26.jpg)
REPEATING SEQUENCES
Plus (+) operator indicates that the preceding character can exist one or more times [RegEx]::IsMatch(“srvfile1”,”srv[a-z0-9]+”) [RegEx]::IsMatch(“srvfile1”,”srv[a-z]+[0-
9]”) [RegEx]::IsMatch(“Monday”,”Mon(day)?”)
![Page 27: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/27.jpg)
REPEATING SEQUENCES (2)
star (*) operator indicates that the preceding character can exist zero times or more times [RegEx]::IsMatch(“Ann”,”Ann[a-z]*”)
Repetitve Format [RegEx]::IsMatch(“96813”,”[0-9] [0-9] [0-9]
[0-9] [0-9]” [RegEx]::IsMatch(“96813”,”[0-9] {5}”
![Page 28: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/28.jpg)
REPEATING SEQUENCES (3)
Repetitve Format [RegEx]::IsMatch(“96813”,”[0-9] [0-9] [0-9]
[0-9] [0-9]” [RegEx]::IsMatch(“96813”,”[0-9] {5}” [RegEx]::IsMatch(“USERA”,”USER[A-Z]
{2,5}”) Ends in a sequence of two to five upper case
letters
![Page 29: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/29.jpg)
ANCHOR TO MAINTAIN POSITION
^ - the match must occur at the beginning of the string [RegEx]::IsMatch(“SRVFILE1”,”^SRV[A-Z]
+[0-9]”) [RegEx]::IsMatch(“TESTSRVFILE1”,”^SRV[A
-Z]+[0-9]”)
![Page 30: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/30.jpg)
ANCHOR TO MAINTAIN POSITION (2)
$- the match must occur at the end of the string [RegEx]::IsMatch(“SRVFILE1”,”SRV[A-Z]
+[0-9]$”) [RegEx]::IsMatch(“TESTSRVFILE1”,”SRV[A-
Z]+[0-9]$”) [RegEx]::IsMatch(“SRVFILE1TEST”,”SRV[A-
Z]+[0-9]$”)
![Page 31: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/31.jpg)
COMING UP WITH ALTERNATIVES
[RegEx]::IsMatch(“Dummies.com”,”[A-za-z0-9]+\.(com|edu|net)”)
![Page 32: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/32.jpg)
REGEX IN WINDOWS POWERSHELL
$email = “[email protected]” If ($email –match “[A-za-z0-
9][email protected]”){ Write-Host “$email is a dummies.com
email address” }
![Page 33: Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+](https://reader035.vdocuments.net/reader035/viewer/2022062722/56649f295503460f94c43107/html5/thumbnails/33.jpg)
REGEX IN WINDOWS POWERSHELL (2) $str = “Visit us at www.dummies.com” $newstr = $str –replace “www\.[A-za-
z0-9]+\.(com|edu|net)”,”WEBSITE NAME KEPT SECRET”
Write-Host $newstr