Power Shell 2 Scripting : Create a new Windows log called Activity13_1 and assign a provider

by May 5, 2013

Would someone from this forum help me with my PowerShell Assignment please?

I am not so good at powershell and not getting help from the instructor at all. Need this done very soon. so Please help with this scrip. Thank you.

 

Activity 1: Scan for changes to a file

  •  This script
    will look for changes to a file every few seconds. Upon
    finding changes, it will write status log entries.
  • This script should do the following:

    1. Create a new Windows log called Activity13_1 and assign a provider
    2. Create a new file named "c:tempmytarget.txt"
    3. Add a few lines of text to it
    4. Assign the value "NO" to a variable called $trigger
    5. Assign an empty string to a variable called $old_len
    6. Assign an empty string to a variable called $old_writetime
    7. Create a while loop that will loop until $trigger is equal to "YES"
    8. Write a log entry stating that your script is starting up
    9. Inside of the loop:
      • Check to see if the file exists; if it does not,
        write a log entry to your new log stating that the script is
        terminating with error, set $trigger equal to "YES", and then continue the loop
      • Get file information for your file using Get-ChildItem
      • If $old_len and $old_writetime are empty strings, set your variables equal to the Lengh and LastWriteTime properties from your object and then continue the loop
      • Assign the Length of your object to a new variable called $curr_len
      • Assign the LastWriteTime of your object to a new variable called $curr_writetime
      • Compare the old and current variables:
        • If both sets of variables are equal, then sleep the script for 5 seconds and then continue the loop
        • If the length variables are different, write a log entry describing your findings, sleep the script for 3 seconds and then continue the loop
        • If the writetime variables are different, write a log entry describing your findings, sleep the script for 3 seconds and then continue the loop
  • Test the script in Powershell
  • Experiment with deleting the file, changing the file
    name, and/or changing the file contents while the script is running.
    Ensure that log entries are being written to your log.

Activity 2: Scan for open ports

  • This script
    will look for the existence of an open port every 60
    seconds. It will write status log entries of its findings.
  • This script should do the following:
    1. Create a new Windows log called Activity13_2 and assign a provider
    2. Assign the value "NO" to a variable called $trigger
    3. Assign the value ":61300" to a variable called $target_port
    4. Create a while loop that will loop until $trigger is equal to "YES"
    5. Write a log entry stating that your script is starting up
    6. Inside of the loop:
      • Execute "netstat -a" and assign its output to a variable called $curr_output
      • Create a foreach loop to iterate over the contents of the array in $curr_output
      • For each element in the loop:
        • If $target_port is contained in the
          line then check to see if the string "LISTENING" is found within the
          line as well;
          if both strings are found within the line then
          write an entry to the log stating your find; sleep the script for 60
          seconds and then continue the loop
        • If $target_port is contained in
          the line and "LISTENING" is NOT found, then write an entry to the log
          stating your find; sleep the script for 60 seconds and then continue the loop
        • If $target_port is NOT contained in the line then write an entry to the log stating your find; sleep the script for 60 seconds and then continue the loop