https://github.com/ggfevans/powershell-compare-directories
A simple PowerShell script for comparing two directory structures to identify file differences.
https://github.com/ggfevans/powershell-compare-directories
compare directory powershell system-administration-tools
Last synced: 8 months ago
JSON representation
A simple PowerShell script for comparing two directory structures to identify file differences.
- Host: GitHub
- URL: https://github.com/ggfevans/powershell-compare-directories
- Owner: ggfevans
- License: mit
- Created: 2025-04-11T20:17:53.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-04-11T22:08:53.000Z (12 months ago)
- Last Synced: 2025-04-23T15:15:56.459Z (12 months ago)
- Topics: compare, directory, powershell, system-administration-tools
- Language: PowerShell
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# powershell-compare-directories



A simple PowerShell script for comparing two directory structures to identify file differences.
## Compare-DirectoryStructure.ps1
This script helps identify:
- Missing files between directories
- Files with different sizes or timestamps
- Optional content comparison with MD5 hashes
## Requirements
- PowerShell 5.1 or higher
- Works on Windows, macOS (with PowerShell Core), and Linux (with PowerShell Core)
- No additional modules required
- Standard user permissions (admin privileges not required unless comparing protected directories)
- Sufficient memory for large directory comparisons (memory usage scales with the number of files)
The script is designed to be cross-platform compatible with minimal dependencies, making it easy to use in various environments.
## Usage
```powershell
.\Compare-DirectoryStructure.ps1 -folderA "C:\SourceFiles" -folderB "D:\BackupFiles"
# With additional options
.\Compare-DirectoryStructure.ps1 -folderA "C:\SourceFiles" -folderB "D:\BackupFiles" -showProgress -checkContent -outputFile "results.csv"
```
## Parameters
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `folderA` | String | Yes | Source directory |
| `folderB` | String | Yes | Target directory |
| `outputFile` | String | No | Save results as CSV |
| `showProgress` | Switch | No | Display progress bar |
| `checkContent` | Switch | No | Compare file contents with MD5 |
| `includeMissingFromA` | Switch | No | Find files in B missing from A |
## Installation
### Direct Download
1. Download `Compare-DirectoryStructure.ps1` from this repository
2. Save it to your preferred scripts directory
3. Run it directly using PowerShell
That's it! No complex setup required.
Example:
```powershell
# Navigate to where you saved the script
cd C:\Path\To\Scripts
# Run the script with parameters
.\Compare-DirectoryStructure.ps1 -folderA "C:\SourceFiles" -folderB "D:\BackupFiles"
```
## Sample Output
```
Found 3 differences.
File FolderA_Size FolderB_Size Difference Status
---- ------------ ------------ ---------- ------
config.json 1245 978 Size Different
data.csv 45678 Missing Missing Missing in Folder B
backup.ps1 Missing 2341 Missing Missing in Folder A
Summary:
- Missing in Folder B: 1
- Missing in Folder A: 1
- Different Files: 1
```