Update README.md

This commit is contained in:
2025-02-13 15:17:41 -06:00
parent ae65596a9d
commit 3577ab8062

View File

@@ -0,0 +1,64 @@
#### Readme is AI generated ;)
<details type="reasoning" done="true" duration="86">
<summary>Thought for 86 seconds</summary>
> Okay, I need to write a Readme file for this PowerShell script. Let me first understand what the script does.
>
> So, looking at the code, it's using Get-CimInstance to retrieve user profiles on a computer. It then processes each profile, checking if they're system accounts or in an exclusion list. If not, and if they've been inactive beyond $InactiveDays (set to 14), it deletes them.
>
> The script is designed to run with high impact, so probably needs admin rights. The user has excluded "Administrator" and "Example Profile" by default.
>
> I should start the Readme with a title like "User Profile Cleanup Script." Then explain what it does: automates cleaning up unused local user profiles based on inactivity.
>
> Next, I'll outline features. It checks last use time or login date, excludes certain users, handles errors, and works for both domain and local accounts.
>
> For prerequisites, the script needs to run as admin because of high impact operations. Also, it uses CIM cmdlets which are standard in PowerShell on Windows.
>
> How to use section: Save as .ps1, run with PS as admin. Maybe mention excluding specific users by modifying $ExcludedUserNames.
>
> Parameters and settings: Explain each variable like ExcludedUserNames, InactiveDays, etc. Mention that wildcard * can be used for exclusion patterns.
>
> Important notes include not running it on production without testing, backing up profiles if needed, and ensuring exclusions are correctly set to avoid deleting necessary accounts.
>
> Troubleshooting should cover common issues like access denied (run as admin), no profiles found (check inactivity days setting or exclusions), errors during deletion (maybe profile is loaded).
>
> Contact info: Suggest reaching out via email for questions.
>
> I think that covers the main points. I'll structure each section clearly, using bullet points where possible for readability.
</details>
# User Profile Cleanup Script Readme
## Overview
This PowerShell script automates the process of identifying and removing inactive or unused user profiles on a Windows computer. It is designed to help maintain system performance by eliminating unnecessary files associated with old or unused accounts.
## Features
- **Identifies Inactive Profiles:** The script calculates the number of days since the last login or profile use and compares it against a specified threshold (`$InactiveDays`).
- **Exclusion List:** Certain user accounts can be excluded from deletion based on predefined criteria.
- **Error Handling:** Robust error handling ensures that issues during profile cleanup are reported, preventing potential data loss or system instability.
- **High Impact Operations:** The script is configured to run with high impact operations, ensuring it operates with the necessary privileges.
## Prerequisites
1. **Administrator Privileges:** The script must be executed with administrator privileges due to its high impact operations.
2. **PowerShell Environment:** Requires a PowerShell environment on Windows capable of running CIM cmdlets.
3. **Local User Profiles:** Works best when dealing with local user profiles, though it can handle domain accounts as well.
## How to Use
### Step 1: Save the Script
Download or copy the script into a `.ps1` file.
### Step 2: Review and Modify Settings
Before execution:
- **Excluded User Names:** Adjust the `$ExcludedUserNames` array to include any user accounts you wish to protect from deletion. This can include wildcard patterns (e.g., `"Example*"`).
- **Inactive Days Threshold:** Set `$InactiveDays` to determine how many days of inactivity are required before a profile is eligible for deletion.
### Step 3: Execute the Script
Run PowerShell as an administrator and execute the script:
```powershell
.\UserProfileCleanup.ps1
```
If you get a policy error about not being able to execute the script copy and run the contents of ((ExecutionPolicy.md)[https://git.archfox.org/poslop/DeleteOldProfiles/src/branch/main/scripts/ExecutionPolicy.md#run-this-to-allow-ps-execution])