Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Introduction Assignment # 1 - PowerShell You are working as a system administrator in your company. One of the software engineering teams were complaining
Introduction Assignment # 1 - PowerShell You are working as a system administrator in your company. One of the software engineering teams were complaining to you about the storage on the development servers are critically low. This has been an issue happening repeatedly. A previous team member in their team used to take care of this manually by freeing up the space. During your investigation, you found out that there are lots of logs being written by one of the applications. You discussed the reason behind having such logs and if they are necessary or not. The software engineering team investigated the logs and found out that such logs are important to be capture while developing their applications. As a proactive system administrator, you held multiple brainstorming sessions with the engineering team to find a solution for such an issue. The most appealing solution out of the discussions was to delete the old logs. You gathered all the requirements below that need to be implemented. Requirements 1- Create a log file clean up automation 2- The script will be reading a csv (comma separated value) file and the number of days to go back to delete a file if it was created before then 3- The script will print out on the screen the files that were deleted as it is running 4- Some of the files and folders must not be deleted in the logs folder 5- The software engineering team will need to be handed over that script and they will be running it whenever they want Also, as part of the discussions, you agreed on the below assumptions. Assumptions 1- The logs are going to be in a folder named logs on the C drive 2- The script will not ask for confirmation from the user to remove file by file, i.e., once the script starts running, it will start deleting the logs without more confirmations from the user 3- The csv file will be having the following headers: DirectoryPath: this is the directory of the files that needs to be deleted FileName: the file name that will be deleted under such a directory KeepForDays: the number of days to keep a file. If 0, this means the file is going to be deleted when the script is run. If more than 0, then you will need to delete only the files that were created before such number of days Sample couple of entries in the csv file: DirectoryPath,FileName, KeepForDays C:\test\logs,1.log, 0 C:\test\logs,2.log, 5 Here are some of the tips that you can think of to approach having a robust solution. Tips 1- You will need to create variables to hold on the csv file location. Variables use $ before the variable name. 2- To import the csv file, you will need to use Import-Csv and use the parameter path. Something like: Import-Csv-path 3- The csv file will be having multiple rows, you will need to have a loop. Recommendation is to use foreach. Example of a foreach is: foreach ($i in $items) { } 4- Inside the loop, you will need to filter only on the files exist in the list. Hit here is to use Get-ChildItem and filter on the file name. 5- You can use: $(Get-Date).AddDays method to get the current date and add days to it 6- To remove an item, you can use Remove-Item, and to disable confirmation from the user, check Confirm: parameter 7- You can use Verbose for printing the files to be deleted
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started