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:
- Create a new Windows log called Activity13_1 and assign a provider
- Create a new file named "c:tempmytarget.txt"
- Add a few lines of text to it
- Assign the value "NO" to a variable called $trigger
- Assign an empty string to a variable called $old_len
- Assign an empty string to a variable called $old_writetime
- Create a while loop that will loop until $trigger is equal to "YES"
- Write a log entry stating that your script is starting up
- 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.
|