This weekend, we faced the task of migrating a file server to a new location while enabling the Microsoft Deduplication feature on the destination server. My goal was to minimize the disk size during this process, which is why I consistently ran the deduplication command on the disk volume as I transferred data.
To streamline this process and avoid having to type the command each time, I created a PowerShell script. Iām excited to share this script on my GitHub page, along with all the necessary information to help you get started.
About the Script
The script automates the deduplication process by starting deduplication jobs with the type set to “optimization.” This means that it will efficiently identify and remove duplicate data, thereby reducing the disk space used.
You can find the script on my GitHub page.
Script Overview
MSDeduplicationScript.ps1
is a PowerShell script that provides a menu-driven interface to manage deduplication jobs on a specified volume (D: in this case). Users can:
- Start a deduplication optimization job.
- Retrieve current deduplication job statuses.
- Check the overall deduplication status.
- View live deduplication status updates.
- Exit the script.
How to Use the Script
Open PowerShell:
Open PowerShell with administrative privileges. You can do this by right-clicking the PowerShell icon and selecting “Run as administrator.”
Set Execution Policy (if needed):
If you haven’t run scripts before, you may need to set the execution policy. You can do this by entering:
powershell
Set-ExecutionPolicy RemoteSigned
Run the Script:
Copy and paste the entire script into your PowerShell window or save it as MSDeduplicationScript.ps1 and run it using:
.\MSDeduplicationScript.ps1
Example Outputs
1. Menu Display
When you run the script, you will see the following menu:
2. Log File Structure
The script writes logs to C:\ITLog
. Below are examples of what you can expect in each log file:
DedupOptimizationLog.txt
2024-10-27 14:20:01 - Started Deduplication Job (Optimization) on Volume D at 02:20 PM on Saturday:
2024-10-27 14:22:45 - Completed Deduplication Job (Optimization) on Volume D that started at 02:20 PM on Saturday and finished at 02:22 PM on Saturday.
DedupStatusLog.txt
2024-10-27 14:25:01 - Retrieved Deduplication Status:
FreeSpace SavedSpace DedupPercentage Volume
------------ ------------ -----------------------
500.00 GB 200.00 GB 28.57%
Important Notes
- Ensure that the deduplication feature is enabled on the volume (D:). You can check this via Windows Server settings or through PowerShell commands.
- You can modify the volume from
D:
to any other volume by changing the script where it specifies the volume in theStart-DedupJob
function.
Summary
MSDeduplicationScript.ps1
is a powerful tool for managing deduplication jobs in Windows environments. By using the menu-driven interface, you can easily start jobs, check their statuses, and monitor deduplication performance in real time, with logs that help you keep track of operations performed.
Thank you for reading, and I hope this guide helps you while using my script. If you have any questions, feel free to leave a comment.
Wishing you a successful day!
Best regards,
Hasan