Professional Documents
Culture Documents
Week 3 Topics
Nirmal Anam
Matthew Cubis
Topics
Detour to Additional Features of Powershell
Reserved Words (Slide 3)
Escape Characters (Slide 5)
String Manipulation (Slide 7)
Storing and Retrieving Data
Variables (Slide 11)
Arithmetic operators (Slide 13)
Assignment operators (Slide 21)
Arrays (Slide 26)
Hashes (Slide 30)
Using Single Quotes and Double Quotes (Slide 32)
Data Types (Slide 38)
Large arrays become hard to manage (searching through each element is tedious).
Associative arrays also referred to as Hash or Dictionary, allows us to store data
in key-value pairs.
You can assign values from hashes into other variables: $y = $x[345]
Keys and values can be of any length. Amount of time to retrieve data is fast and
doesnt increase even with more values.
Associative arrays can be combined too: $y = $x + $superhero
Data Types
Powershell variables can contain various types of
values.
For Example:
$x = 2 (we are storing a number, so it is of the type
Integer, referred in powershell as int32
$x = Hello (Here we are storing a text value, it is
of type string, referred in powershell as string)
There are a number of data types a variable can
have.
Data Types
Powershell variables can contain various types of values.
For Example:
$x = 2 (we are storing a number, so it is of the type Integer,
referred in powershell as int32
$x = Hello (Here we are storing a text value, it is of type
string, referred in powershell as string)
There are a number of data types a variable can have.
Generally powershell accepts a value of any data type to be
stored in a variable. But sometimes there could be a situation
where you want to force a variable to accept a value of a
certain data type. Example is given in the next slide.
Data Types
By default read-host accepts and stores a value as string which
sometimes wont be suitable for our purpose:
Both times 12 is stored as text (default data type while using readhost). We know that the + operator combines two text values just
like combining two words.
Data Types
We can force $X and $y to store values as numbers and not text:
Data Types
Other types of commonly used data types for
variables are:
[Int] : Integer numbers
[string] Text or string of characters
[single] and [double] : floating point numbers
(numbers with decimal portion)
[char] : Exactly one character
[xml] : An xml document
Task 1 (DIY)
This task will be based on all the concepts
learnt in this week Variables, Arrays, Hashes,
Operators, Escape Characters, String
manipulation.
Conclusion
Objective
By the end of this section you should understand
the usage of variables, arrays, hashes clearly. You
should have an understanding on how to use the
various types of operators and data manipulation
techniques including escape characters and the
difference between using single and double
quotes.
References
Learn Windows Powershell 3 in a month of
lunches, second edition by Don Jones and
Jeffery Hicks
Microsoft Windows Powershell Programming
for the absolute beginner, third edition by
Jerry Lee Ford Jr.