Uploaded by Deo Madrid

CENG214-Assignment4-F2021

advertisement
Out: Group C & A: Oct 12, Group B: Oct 15
Due: Group C & A: Oct 19, Group B: Oct 22
Same date as your class, 11 pm
CENG 214 Assignment #4
For this assignment log in to your PC as your Administrator account as you will need this to add several
users. Develop all scripts using VS Code. A number of the exercises posed in this assignment are
designed to review problems students had in #2. Pay close attention to the requirements, especially the
requirements of testing. Marked out of 30.
Part I: Demo (4 marks)
Download the file Oct12Demo.txt from the course web site. Load it into Visual Studio Code
and then save it as a PowerShell .ps1 file. Work your way through the demo as it is presented
in class. Write up your own notes for each section of the demo summarizing the new material.
Hand in your notes with your final report.
Part II: Programming Exercises
1. Strings vs Numbers
Write a short script that prompts and inputs 2 numbers. The first should be between 3 and 9.
The second should be between 100 and 250. Compare the two numbers and have the code
report which is the larger and which is the smaller of the two. (2)
2. Generate the lyrics to a silly song (4 marks)
a. Write a short script that generates the lyrics for the song “99 bottles of beer on the
wall”. The Wikipedia article explains what this is and provides code in several languages
other than PowerShell: https://en.wikipedia.org/wiki/99_Bottles_of_Beer
and I’ve provided a web page that illustrates it for a lower number.
http://apollo.humber.ca/~king/CENG214/bottles.html
However the 1st line of your output should contain your name and the time and date the
script ran. (2 marks)
b. Modify your code so that it writes the lyrics to a file and then displays it automatically in
Microsoft Word. (Refer to the code that references notepad and excel for hints),
Prove that it worked by handing in the generated file (2)
3. Generating Random Hash Tables (6 marks)
In Assignment #1 Part 2 exercise #6 you had to generate a random hash table and create 3
output examples. If you did not succeed review the take up of this and make sure you have a
working example.
a. Write a script in the VS Code environment that prompts your for a number which
should be between 4 and 9. Loop to generate that number of random hashtables and
add these hashtables into an array. The result is an array of hashtable objects. Use the
.getType() method to verify this both for the array and for the last element of your
array. (2)
b. The -join operator is the inverse of the -split operator, creating a string from an array.
Using the .keys() method of the datatype hashtable, generate a csv (comma separated
values) string of your keys and output the result first to the screen and then to a file
with the extension .csv. This should create a file with 1 line. If your hashTable looked
like $student1 from the demo the output line would be: Semester,GPA,name (1)
c. Loop through the array created in a. Convert each set of values to a csv delimited string
and append each string one line at a time to your file. (1)
d. Modify your program so that the file can be opened in Excel so that the hash table’s
field names appear in separate columns in the 1st row and the field values appear in
separate columns in the remaining rows.
Use get-content in your script to verify the contents of your file.
Provide a screen shot showing your data in Excel as we did in Demo #5 (2)
4. Checking Lottery Numbers (8 marks)
a. Run the code that creates the file lottery.csv so you have a copy of the file but reduce
the # of tickets generated to 5. (1)
b. Manually create 3 non-random lottery tickets with the following criteria (1)
i. The first matches all 7 values of one of the tickets from the file
ii. The 2nd matches 3 of the 7 values of another of the tickets
The other 3 values should come from your 1st ticket
iii. The 3rd matches only 1 of the 7 values of a 3rd ticket
The other 6 values should come from your 1st ticket.
c. In your script write a loop that determines the number of matches between 2 tickets. (3
marks)
i. Test it by matching a ticket against itself. You should get a count of 7
ii. Test it by matching the 1st ticket against the 2nd. You should get a count of 4,
possibly more but unlikely 7.
d. Based on the code to read in the lottery.csv (see Demo5) and the above, write another
script that checks the 3rd ticket against all the tickets in the file. For each ticket report
the number of matches. One of the tickets should report 6 matches, another should
report No bets on what anything else reports. (3)
5. Administrative task: create a group of users using a PowerShell script. (6 marks + 2 bonus)
This is a continuation from Assignment #2
Create a file consisting a group of 4 new user names and passwords and descriptions, 1 to a line.
a. Write a script that does the following (3 marks)
i. Write a loop reads in the file and prints out just the user names one at a time.
Make sure that this works before doing moving on to the next step.
ii. Convert each password to a secure string
iii. Have your script create an account using localuser for each of the users
Add each of these users to the local group Users
iv. Hand in your script and proof that all of the users listed have been created.
Remember – no directories or files are created for users until they log in – you do
not have to actually log in.
b. Review verbs that work with localuser using get-help. Create a file that consists of 2
fields – the user name (taken from part a) and a full name. The names should be in a
different order than before. Write a script of that sets the full names of the users based
on the contents of this second file.
In your report hand in your script, any files you created, proof that it worked and write
up a description of your design. (3 marks)
c. Bonus: Write a script that reads the 1st file and removes the listed accounts. (2 marks)
Create a report that includes all your code and proof that each exercise worked. You may
provide screenshots of output but your code must be a text listing. Use Heading1 and Heading2
formatting to index the start of each question.
Download