Windows
CLI
Day 1
Command Line Tool Output
Importance
could make or break your operation
GUI may not be available
Often times a command line tool must be used
Basic Native Commands
set
where
echo
dir
type
findstr /I /R word
hostname
date /t
time /t
Batch (.bat)
allows for automation of tasks
Native Command Redirection
> and >>
Piping ( | )
Conditional processing symbols
& and ;
&&
||
Nesting
ACTIVITY
Windows Batch Script
(Using only CMD commands)
WMIC Command Basics
wmic /?
wmic process /?
wmic service
wmic useraccount
wmic nicconfig
wmic nteventlog
list brief
ACTIVITY
Windows Batch Script using only WMIC commands
Day 2
Powershell
Powershell ISE
Different versions
Commandlets (cmdlets)
Powershell Continued
Why use powershell?
<INSERT VERBS FROM PS HERE AND EXPLAIN>
Object oriented
Get-help <content>
Get-help <command>
Powershell Continued
CLI output
Powershell Output
Object Definition
Properties = data
Methods = functions or actions to take on properties.
Tasklist | get-members VS get-process | get-member
Compare the different control you have over the 2 commands
Address properties or methods
object.<propertyName> --OR-- object.<method>(args
Main Components of Powershell
Internal and external commands. (?)
External = spawn new process
attrib
Internal = runs inside powershell process
ping, dir
Cmd.exe is ppid of all internal commands. (?)
Objects:
The output from a powershell command is an object.
Classes:
General term for grouped objects
WMIC and CIM
Common Information Model (CIM): meant to be cross platform
Windows Management Instrumentation (WMI) is windows specific
More Components of Powershell
Variables:
$a=”Hello World”
Command substitution:
$(get-process).name
Looping:
$(get-process).name | foreach-object {echo “$_ is a running process”}
$a=1..5; foreach ($i in $a) {echo “$i is a number”}
$x=0; while ($x -lt 100) {echo “this is loop number $x”; $x++}
Indexing:
$(get-process)[4] --OR-- $(get-process)[0..4]
**Indices always start at 0**
More Components of Powershell
Arithmetic:
1+1 == 2
1 + “dog” == “1dog”
“cat” + “dog” == “catdog” (strings concatenate)
$a=”1”; $a+1 == “11”
Because $a is a string. Use a typecast to avoid this: [int]$a+1 == 2
While ($true) {$date = get-date -format hh:mm; if ($date -eq “05:00”){break}}
Functions
A list of commands that, when together, serve a purpose.
Ex. Function dostuff {get-date; get-process; get-service}
Once the function has been declared, you simply issue the name of the function as a command and it will execute the commands inside the function.
More Components of Powershell
Multithreading
A technique that allows a single set of code to be used by several processors at different stages of execution.
To multithread in Powershell, use jobs
https://www.youtube.com/watch?v=4QnJPCqaOWQ
https://www.youtube.com/watch?v=kj98OhCW-xs