Beruflich Dokumente
Kultur Dokumente
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
Get-EventLog system et error -before 18/09/2015 -after 16/09/2015 | Sort-Object -property index
Page 1 of 5
336108411
5) Write and paste here a piece of code that:
Counts the number of warning messages in the system event log for today.
Page 2 of 5
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 )
Technical Requirements
Write
i.
ii.
iii.
iv.
v.
vi.
vii.
Page 3 of 5
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.
Page 4 of 5
336108411
Test Case
Expected Result
Actual Result
Empty attachment
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