Final exam part 2
Publication date: 2025-07-09 13:00
Submission date: 2025-07-09 15:00
Submission mode: Omnivox
Modality: Individual exam
Authorized material: Course notes, your practical work and exercises, online documentation, but no external help (no communication with other people)
Use of AI: According to the College policy. You can use AI for research, but the code must be entirely written by yourself.
Automated System Logs Management Script
Context
You are a system administrator in a company. Your manager asks you to create a PowerShell script to automate the management of log files. This script should allow for the regular cleaning, organizing, and analyzing of logs.
Work Objectives (100 points)
Your PowerShell script must automatically perform the following actions:
1. Creation of the work environment (25 points)
Your script must use the environment variable ENTERPRISE_DATA (already defined with a valid path, for example C:\EnterpriseLogs) to automatically create the following folder structure in $env:ENTERPRISE_DATA\AdminLogs:
$env:ENTERPRISE_DATA\AdminLogs
│
├── Logs_Actuels
│ ├── Systeme
│ ├── Applications
│ └── Securite
├── Archives
│ └── Anciens
└── Rapports
The folders might already exist. Your script must check their existence and not cause errors if the folders are already present.
Then, the script must also create 5 fictitious log files in the Logs_Actuels\Systeme folder:
system_2025-07-01.log(content: "INFO: System startup successful")system_2025-07-05.log(content: "ERROR: Hard drive error")system_2025-07-08.log(content: "WARNING: Low memory")system_2025-07-09.log(content: "INFO: System up to date")old_system_2024-12-15.log(content: "INFO: Old log")
2. Analysis and search in logs (25 points)
Your script must:
- Search for all
.logfiles in the$env:ENTERPRISE_DATA\AdminLogs\Logs_Actuelstree - Create a list of files containing the word "ERROR" and save it in
$env:ENTERPRISE_DATA\AdminLogs\Rapports\erreurs_trouvees.txt
3. Automatic archiving (25 points)
Your script must:
- Identify all log files older than 7 days (use the date in the file name)
- Move these old files to the
Archives\Anciensfolder and rename them by adding the prefixARCHIVE_- Example:
old_system_2024-12-15.log→ARCHIVE_old_system_2024-12-15.log
- Example:
Be careful, there might already be files in the Archives\Anciens folder. Your script must not add ARCHIVE_ to files already archived. (So there should not be a file named ARCHIVE_ARCHIVE_old_system_2024-12-15.log)
Your script can overwrite an existing file if the name is identical.
4. Final report and verification (25 points)
Your script must generate a final report (rapport_gestion_logs.txt) in the $env:ENTERPRISE_DATA\AdminLogs\Rapports folder containing:
- The date and time of the script execution
- The number of archived files
- The number of files containing errors
- A confirmation message: "Script executed successfully"
Technical Requirements
-
Script structure: Your script must be well organized with comments explaining each important section.
-
Idempotence: The script must be able to be executed multiple times without causing errors.
Useful PowerShell Commands
New-Item: Create files and foldersSet-Content/Add-Content: Write to filesGet-ChildItem: List files and foldersSelect-String: Search text in filesCopy-Item: Copy filesMove-Item: Move filesRename-Item: Rename filesTest-Path: Check the existence of a file/folderGet-Date: Get the current date
Deliverable
You must submit your PowerShell script named gestion_logs.ps1 on Omnivox.
Good luck!