CENG 214 Assignment #1
嚜燈ut: Week of Sept 20th
Due: 8 pm the date before your scheduled class, Week of Sept 27th, no late submissions
+10% 8 pm two days before (or earlier)
# of marks: 26
CENG 214 Assignment #1
Parts I and II should be submitted as separate files.
Part I: In Class Demo - PowerShell Variables and Operators (10 marks)
Follow along with the class demo. Feel free to try some variations on the individual commands.
After changing a value or set of values display the result of the change by entering the variable
name. After the 1st step you can leave out the comments. Hand in a transcript of your session. No
screen shots 每 text only!!!!
Do not cut and paste from the assignment text!!! You learn by trying things out and you should
try your own variations. Also, PowerShell (and Unix) expects single byte ascii quotes: " " ' '.
Word processors use Unicode quotes like this ※ ※ & & which are multibyte codes.
For each for the following exercises enter the exercise # and description comment as a title before
entering the command. This will make your transcript self documenting. After you saved the
transcript, use Word or OpenOffice to edit the transcript. Remove any errors and long outputs
more than 10 lines. Change the format of the exercise headings to ※Heading 2§. This will make
each section easier to pick out and create a navigation pane on the side.
The report for Part I should be no longer than 6 to 8 pages. If it*s more than 12 it*s too long to
mark.
1. Start up PowerShell from the Windows control. Issue the following command:
start-transcript -path yourName-Lab1.dat
When you are done issue the following command
stop-transcript
If you wish to restart your session after stopping it:
start-transcript -path yourName-Lab1.dat -append
2. Comments - try this out!
a. #This is a comment
b.
3. Calculations in the shell:
a. 21*5 #try a couple more with different operators
b. 21*5.7
c. [int](21*5.7) #The cast operator
d. #try some additional numeric operators to see if they work
e. 10..15 #generates a range of numbers
f. 10..15; 12..-2
g. ※File§ + ※Name§ #concatenation
h. (12).getType() #determine the data type
i. get-date
#displays current date and time;
4. Variables: (All variables start with a $)
a. $x=79%10; #To display, just type in $x alone on a line
b. $now=get-date
c. $now.getType()
d. $fileName=§File§+$x #What is the file name
5. Arrays
a. $myArray=@( 5; 12*2.7; get-date ; -7..5; ※Hello World§)
b. $array2=*c*..*f*,5..9,12,3,get-date #alternate way to express arrays - this does not work
get-error #detailed description of problem
$error=get-error
$error.Exception.Message #extracting the short error message
(get-error).exception.message #same result but intellisense not available
$array2=(&c*..**f*),(5..9),12,3,(get-date) #this does - add brackets around expressions
c. $myArray[0]
d. $myArray[2]
e. $myArray[3]
f. $myArray[0]*=7
g. $myArray.count # # of items in the array
h. $myArray[40]=72 #Does not work. Out of range.
i. $myArray+=§Again§ #Adding to an array is easy
j. $myArray+=1..10
k. $myArray.count
6. Hash Tables 每 Use {} not ()
a. $person= @{ name=§your Name§ ; age = 20; birthDay=get-date}
b. $person.name #type in person. and repeat the to explore
c. $person[&age*]
d.
e.
f.
g.
h.
i.
j.
k.
$person.keys #We can isolate both the keys and values of a hash table
$person.values
$person.count
$person+=@{Vehicle=*Maserati*; licence=*SPEEDY 5*} #add fields
$person.school=§Humber§
$person.vehicle=§Mini Cooper§ #reset the value
$person #show the table
$person.remove(&licence*); $person #Remove licence and show modified person.
7. Working with data Providers: Get-Date
a. $x=Get-Date
b. $x.
#Treat this as a hash table 每 explore retrieving values
get
# moves one in the other direction
c. $x.add
#Look at the available functions
d. $x.subtract
8. Working with Help
a. update-help
#Do this once
b. get-help get-date
#Short form of help
c. get-help get-date -verbose
d. get-help get-date -Detailed
e. help get-date -online #brings up a new window with online help
f. help get-date -showWindow #Presents a GUI to fill out command
9. Working with the data provider get-random
a. get-random
#generates a random integer
b. get-random 20
#generates a random integer from 0-20
c. get-random 20.0 #generates a random double from 0.0 to 20.0
d. 1..49 | get-random -count 6 #Generates a Lotto 6/49 #
e. $myArray | get-random -count 3 #picks 3 items from $myArray
f. $slots=§cherry§,§bell§,§plum§, ※bar§,§orange§,§bar§,§lucky 7§,§diamond§, ※lemon§,
※horseshoe§
g. $slots | get-random -count 5
h. get-random $slots -count 5
i. $display= @(get-random $slots; get-random $slots; get-random $slots)
j. $display2=$(get-random $slots), $(get-random $slots) #$( ... ) - subexpression operator
10. Testing conditions on Numbers, arrays and Strings
a. 7 -lt 12
#Result is true or false. Works with variables
b. 8 -eq &8*
c. # other operators are: -le -ge -gt -ne; > < != and == do not work!
d. &Hello* -eq &hello* #string comparison is case insensitive
e. &Hello* -ceq &hello* #Add a c in front of the operator to make it case sensitive
f. 6 -in $myArray
#Should be True
g.
h.
i.
j.
99 -in $myArray
#should be False. -cin is the case sensitive version
$myArray -contains 6 #The only difference is the array occurs first; also -ccontains
$string=§What the heck is this?§
$string -like ※*heck*§ #Check if 2nd string ※heck§ appears in 1st string
#* is a wild card matching 0 or more characters
k. $string2=§heck§;
l. $string -like ※*$string2*§
# Using double quotes means $string2 is evaluated.
#See also -clike
Reference:
11. Issue the command: stop-transcript
Use MS-Word or Libre Office Write to edit the transcript. Hilite each of the headings at the start
of exercise 2-10 using bold and blue text 每 the Heading 2 style will do this. Submit the modified
transcript in BlackBoard as Part 1 of your assignment. (10 Marks)
Part II: Trying it out on your own (16 marks)
Reminder: Part II of the assignment should submitted in a separate file. Use comments and
level 2 headings. The report should be 2-4 pages.
Write a report showing tests of the following. If you use a transcript, edit out all failed attempts and use
search and replace to remove extra text such as the command line prompt. Don*t reproduce the
questions below but use the same outline scheme to identify your answers.
In other words 每 your report should be easy to read and mark.
1. Working with operators (4 marks)
a. Create a demonstration of 2 different numeric comparison operators listed but not
demoed using doubles.
b. Create a demonstration of 2 different string comparisons, one case sensitive, the other
not, other than -eq and -ceq which were demonstrated.
c. Provide an example of a case where -in and -cin produce a different result
d. Both -in and -contains work with arrays. Create an array and then provide a test of
-cin and -ccontains.
2. Hash tables: (3)
a. The exercises cover how to create a hash table. Create your own hash table using a
theme different than the one used in the demo. For example you could choose to
represent any of the following: animal, appointment, book, clothing, company, desert,
event, formula, graph, instrument, jewelry, label, movie, planet, river, song, tshirt,
weather.... Your hash table should have 3 fields. Do not use the theme of person or
vehicle which was used in the examples
b. Show how you can change the value of one of your fields using both dot and [] notation.
c. Add one or more new fields to an existing version of your object.
3. Get-help on the get-date command (3)
a. List the full command you used to get help
b. List 2 of the switches other than -Format and -UFormat, test them out and describe
what they do.
c. Log on to Unix and compare the date formats used in PowerShell to the date formats list
in the man page of the Unix date command. List two differences between the format
codes. If there are no differences say so.
4. Working with Get-Date (2 marks)
a. Start with $x=Get-Date. Use the add functions to generate your birth date. If you know
the time, generate that too. If you don*t, make up a time that is different than the
default time. You can chain functions together by using ( ):
( (get-date).addYears(5)).addYears(-2000)
b. Use flags such a -Year -Month to create the same date as above.
5. Working with Get-Random (2 marks)
a. Use get-help get-Random figure out how to generate 2 random #s within a range using
flags. Show an example using both integers and doubles.
b. Using the range example and the array example, show whether or not there are no
repeats of the same value. (Hint: try and generate more values than there are in the
list). What commands did you try and what is your conclusion?
6. Combination Problem (2 marks)
a. Revisit your hash table from question 2.
i. Set up 3 arrays containing each containing a set of 5 possible values for each of
the fields, ie: $cars=§Ford Escape§,§Honda Fit§,§Maserati§,§Corvette§,§Jeep§
$age=18..65
ii. Using the above arrays, write a line of code that generates an new hashtable for
your chosen theme in Q2, but generate the values randomly from your arrays.
Create and display 3 of them to verify that they are all different.
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- declaring a byte array in powershell
- ismerkedés a powershellel 2 rész
- layer2 cloud connector user documentation
- declaring a string array c
- powershell new feature in powershell
- challenge 7 solution fireeye
- incommon cm ssl web service api comodo cybersecurity
- windows powershell in action
- ceng 214 assignment 1
- windows powershell batch files on steroids
Related searches
- hud form 214 printable
- hud declaration 214 form
- declaration of section 214 status form hud
- declaration of section 214 status
- declaration of 214 status hud
- hud form 214 citizenship status
- hud section 214 declaration form
- hud section 214 form
- printable declaration 214 status forms
- hud declaration 214 status form
- hud 214 citizenship form
- cs 214 us position description form