Sie sind auf Seite 1von 5

UEE40111 Certificate IV in Computer Systems

Net Admin Fundamentals 2


Units: ICANWK403A, ICANWK402A, UEENEED104A, ICANWK409A

336108411
Setup
1) PowerShell Promt
a. Start a ServerA (or another Windows Server 2012 R2 virtual machine that is a domain
controller it probably doesnt matter if it is a DC 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 as administrator
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

Part A: The components


2) Write and paste here a piece of code that:
Displays the newest 10 messages from the system event log.
Hint: look at the Get-EventLog cmdlet

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


Displays only todays error (error only, not informational or warning) messages from the system
event log.
Hint: [datetime]::Today
Hint: use help to look at the arguments that Get-EventLog has, such as EntryType and After

Get-EventLog system -et error -before 18/09/2015 -after 16/09/2015


4) Write and paste here a piece of code that:
Displays only todays warning messages from the system event log sorted by oldest first.
Hint: look at the the Sort-Object command
Hint: save one EventLog object into a variable, and look at the properties, notice: timegenerated

Get-EventLog system et error -before 18/09/2015 -after 16/09/2015 | Sort-Object -property index

Page 1 of 5

UEE40111 Certificate IV in Computer Systems


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

336108411
5) Write and paste here a piece of code that:
Counts the number of warning messages in the system event log for today.

1..20|%{get-eventlog system -et error -before 18/09/2015 -after 16/09/2015}


6) Create yourself gmail account.
Important: sign onto it once
Important: use defaults for security settings
7) Write and paste here a piece of code that:
Uses the Get-Credential command to create a PSCredential object using your gmail username and
password.
Uses Export-Clixml to export the PSCredential object to a file called C:\Data\mycred.xml
Then examine the contents of the file

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


First: change to a different PowerShell session (File -> New PowerShell Tab).
Second: type in $mycred, notice that it is empty. Good. You may now continue.
Uses Import-Clixml to import a PSCredential object from the file mycred.xml and save it in the
variable $mycred
Print out the retrieved username from $mycred.
9) Try the following piece of code, to see the password in plain text
$mycred.GetNetworkCredential().password

Page 2 of 5

UEE40111 Certificate IV in Computer Systems


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

336108411
10) Execute the following command inPowerShell, and paste the command and its output here:
Note: use you own name instead of yourname
Note: use the same session as the previous question so that $cred is set
Note: you will need to create the file C:\Data\test.txt
Note: you will have to run this from home, unfortunately Chisholms firewall blocks that outbound
port
$mycred = Import-Clixml -Path C:\Data\mycred.xml
$From = $mycred.UserName
$To = "yourname@gmail.com"
$Attachment = "C:\Data\test.txt"
$Subject = "PowerShell email test"
$Body = "Like I said, PowerShell email test."
$SMTPServer = "smtp.gmail.com"
$SMTPPort = "587"
Send-MailMessage -From $From -To $To -Subject $Subject `
-Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl `
-Credential $mycred -Attachments $Attachment
11) Execute the following command in PowerShell, and paste the command and its output here:
After you have successfully executed it, examine the application event log.
New-EventLog LogName Application Source GuruEyes
$m = "Oh noes. Again??!!"
Write-EventLog LogName Application Source GuruEyes EntryType Information EventID 1
Message $m
12) Create a PowerShell script that does something simple, like create a file.
Then, execute it using Windows built in task scheduler.
http://blogs.technet.com/b/heyscriptingguy/archive/2012/08/11/weekend-scripter-use-the-windowstask-scheduler-to-run-a-windows-powershell-script.aspx
Note: your script should be fully automated and not require user interaction
Note: to execute eg every hour, edit advanced (https://support.microsoft.com/en-us/kb/226795 )

Part B: The program


Business Requirements
Daily monitoring of system warnings and errors, with notification by email.
Historical records kept of daily count of system warnings and errors.

Technical Requirements
Write
i.
ii.
iii.
iv.
v.
vi.
vii.

a script which will:


check the system event log
select only warning and error messages from today
sort them to be oldest first
count both the number of warning messages and error messages
send the result (counts first, then the actual sorted messages) as an email
and write the result (counts only) to its own application log
use the task manager to run this script once a day

Page 3 of 5

UEE40111 Certificate IV in Computer Systems


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

336108411
Algorithm (pseudo code or flowchart)
Selecting the errors from the system event log using Get-Event Log and parameters Event Type and
After
Selecting the warnings from the system event log using Get-Event Log and parameters Event Type and
After
Sort the errors and warnings using Sort-Object, sorting by Time Generated
Count the errors and warnings using the count method
Convert the errors and warnings to a string using a for each loop
Save the errors and warnings to a file using Set-Content
Create a new event log source using New-Event Log
Write the error and warning counts to the application event log using Write-Event Log
Make an message to send via email, and send it using Send-Mail Message
Save the script and schedule using windows task manager.
Also create a file containing the mail information.

Program (paste your source code here)


$username = "mgsgz34@gmail.com"
$mycred = Get-Credential -UserName $username -Message "Please enter you gmail username and
password:"
Export-Clixml -Path C:\Data\mycred.xml -InputObject $mycred
$working_dir = "C:\Data"
$mycred = Import-Clixml -Path "$working_dir\mycred.xml"
$From = $mycred.UserName
$To = "mgsgz34@gmail.com"
$Attachment = "$working_dir\attach1.txt"
$Subject = "stuff Report"
$Body = ""
$SMTPServer = "smtp.gmail.com"
$SMTPPort = "587"
$today = [datetime]::Today
$my_errors = Get-EventLog -LogName system -EntryType Error -After $today | Sort-Object -Property
TimeGenerated
$my_warnings = Get-EventLog -LogName system -EntryType Warning -After $today | Sort-Object
-Property TimeGenerated
$error_count = $my_errors.Count
$warning_count = $my_warnings.Count
$Body = "There were $error_count errors today and $warning_count warnings."
New-EventLog LogName Application Source stuff
Write-EventLog LogName Application Source stuff EntryType Information EventID 1 Message
$Body
Send-MailMessage -From $From -To $To -Subject $Subject `
-Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl `
-Credential $mycred -Attachments $Attachment

Page 4 of 5

UEE40111 Certificate IV in Computer Systems


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

336108411

Test Case

Expected Result

Actual Result

Gmail not created

Mail not sent

Mail not sent

Username and password incorrect

Mail not sent

Mail not sent

System log cleared

Empty attachment

Mail wont allow access to the account even


with account asking for user and pass

Mail wont work

Attachment was
empty
Mail didnt work

Signature

Date

Signof
Position
Systems
Programmer
(student)
Client
(instructor)

Name &
Student Id
Ahmad Hijazi

7/10/2015

H201405293
Nathaly Conlan

7/10/2015

Page 5 of 5

Das könnte Ihnen auch gefallen