0% found this document useful (0 votes)
147 views

Lab02 PowerShell - Basics

The document provides instructions for completing PowerShell tutorials on variables, arrays, hashes, conditional logic, and loops. It then provides a series of coding exercises to work through PowerShell concepts like accessing array elements, creating arrays and hashes, type casting variables, working with objects, prompting users for input, and saving/loading data to files. The exercises demonstrate fundamental programming tasks in PowerShell like data storage and retrieval, conditional logic, and basic input/output functions.

Uploaded by

AhmadHijazi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
147 views

Lab02 PowerShell - Basics

The document provides instructions for completing PowerShell tutorials on variables, arrays, hashes, conditional logic, and loops. It then provides a series of coding exercises to work through PowerShell concepts like accessing array elements, creating arrays and hashes, type casting variables, working with objects, prompting users for input, and saving/loading data to files. The exercises demonstrate fundamental programming tasks in PowerShell like data storage and retrieval, conditional logic, and basic input/output functions.

Uploaded by

AhmadHijazi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

UEE40111 Certificate IV in Computer Systems

Net Admin Fundamentals 2


Units: ICANWK403A, ICANWK402A, UEENEED104A, ICANWK409A

336108413
1) PowerShell Tutorials
a. Start a ServerA (or another Windows Server 2012 R2 virtual machine that is a domain
controller it probably doesnt matter for earlier exercises, but it will later). You may want to
install guest additions so that you can cut and paste to your VM.
b. Signon as Superman
c. Run Windows PowerShell ISE
or
You could use just the PowerShell command line, plus an editor like notepad++, note if your
scripts are not local then also run: set-executionpolicy unrestricted
d. Open the web page http://www.powershellpro.com/powershell-tutorial-introduction/
e. Work through tutorials
i. 7 http://www.powershellpro.com/powershell-tutorial-introduction/variables-arrayshashes/
ii. 8 http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorialconditional-logic/
iii. 9 http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/
2) Enter the following commands into your PowerShell session (the following questions will use the
variables/objects created).
$a = Merry
$b = Christmas
$me = Bill
$you = Guru
$names = @(Barry, Harry, Larry, Benny, Penny, Lenny)
$n1 = 4.0
$n2 = 3.0
$n3 = 0.5
$numbers1 = @(1.5, 2.5, 3.5, 4.5)
$numbers2 = @(10.5, 21.5, 23.5, 4.5)
$sentence1 = The quick brown fox jumps over the lazy dog
$sentence2 = That was then, this is now
$user1 = @{ name = Bill; email = [email protected]; address = 22 North Pole; phone =
99999999 }
$user2 = @{ name = Guru; email = [email protected]; address = 1a Mt Everest; phone =
111111111111 }

3) Write and paste here a piece of code that:


Prints the 3rd element of the array $umbers1
$numbers1[3]
4) Write and paste here a piece of code that:
Creates an array of 12 elements, each element contains the corresponding month of the year.
Print the array.
$months
January
February
March
April
May
June
July
August
September
October
November
December

Page 1 of 4

UEE40111 Certificate IV in Computer Systems


Net Admin Fundamentals 2
Units: ICANWK403A, ICANWK402A, UEENEED104A, ICANWK409A

336108413
5) Write and paste here a piece of code that:
Creates a hash where the key is the name of the month of the year, and the value is the number of
days in that month.
Print the hash.
$Monthdays
6) Write and paste here a piece of code that:
Type cast $n3 as an int. Do this by preceding it with [int]. Then assign it to $y.
Print out $y. Print out $y * 4. Print out $y + 4. Print out $y.GetType()
[int]$n3 = 0.5
$y = $n3
0
$y + 4
4
7) Write and paste here a piece of code that:
Type cast $n3 as a string. Then assign it to $y.
Print out $y. Print out $y * 4. Print out $y + 4. Print out $.GetType() .
$y = $n3
[string]$n3 = 0.5
$y = $n3
$y
0.5
$y + 4
0.54
8) Write and paste here a piece of code that:
Type cast $n3 as a double. Then assign it to $y.
Print out $y. Print out $y * 4. Print out $y + 4. Print out $.GetType() .
[double]$n3 = 0.5
$y = $n3
$y
0.5
$y + 4
4.5
9) Write and paste here a piece of code that:
Print out the value of the built in variable $PSVersionTable.PSVersion
$PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- -------4
0
-1
-1
10) Write and paste here a piece of code that:
Assigns $user1 to the variable $y.
Print out $y. Print out $.GetType() .
$y = $user1
$y
Name
---email
phone
name
address

Value
[email protected]
99999999
Bill
22 North Pole

Page 2 of 4

UEE40111 Certificate IV in Computer Systems


Net Admin Fundamentals 2
Units: ICANWK403A, ICANWK402A, UEENEED104A, ICANWK409A

336108413
11) Write and paste here a piece of code that:
Type cast $user1 as PSCustomObject and assign it to $my_object.
Print out $my_object. Print out $.GetType() .
$my_object = new-object psobject Property $User1
$my_object
email
phone
name
address
[email protected]
99999999
Bill
22 North Pole
12) Write and paste here a piece of code that:
Saves $my_object to a file. Hint: use the command export-csv.
Examine the contents of the file.
$my_object | export-csv c:\obj.txt
13) Write and paste here a piece of code that:
Prompts a user for 3 numbers and returns the sum of the numbers. Hint: use Read-Host
$1 = read-host 'JUST DO IT'
JUST DO IT: 1
$2 = read-host 'JUST DO IT'
JUST DO IT: 2
$3 = read-host 'JUST DO IT'
JUST DO IT: 3
$result = $1 + $2 + $3
$result
6
14) Write and paste here a piece of code that:
Prompts the user for their name, address, email and phone number, and stores that information in a
file.
Hint: use PSCustomObject type cast and export-csv command.
$name = @{ name = Bill; email = [email protected]; address = 22 North Pole; phone =
99999999 }
$name | export-csv C:\users\h201405293\desktop\bill.txt
15) Write and paste here a piece of code that:
Opens a file containing names, addresses, emails and phone numbers (ie as produced in the
previous question) and prints them out in a nice format.
Hint: use import-csv
import-csv C:\users\h201405293\desktop\bill.txt
email
phone
name
[email protected]
99999999

address
Bill

-------

22 North Pole

Page 3 of 4

UEE40111 Certificate IV in Computer Systems


Net Admin Fundamentals 2
Units: ICANWK403A, ICANWK402A, UEENEED104A, ICANWK409A

336108413
Signof
Position
Systems
Programmer
(student)
Client
(instructor)

Name & Student


Id
Ahmad Hijazi

Signature

Date
11/9/15

H201405293
Nathaly Conlan

11/09/2015

Page 4 of 4

You might also like