Media Sync: Organize Your Photos and Videos with PowerShell

Do you have photos and videos that you have taken over the years that are scattered all over the place? Do you want to have all your photos and videos organized? Do you want all your photos and videos to have a standardized naming scheme? If you answered YES to these questions, then this is the post for you. In this post, I will provide you with the PowerShell code and examples for how to use the Media Sync script. The Media Sync script utilizes the Shell.Application COM object to gather file metadata. Only files that have a picture or video metadata type will be processed. The script uses the date taken for pictures and the media created metadata fields to organize the photos and videos. If there is no date taken or media created available for a given file, the script will use the modify date instead. The script also ensures that you won’t have any duplicate files by checking the file hashes of the two files in question. If the script detects duplicate files, it will only keep one copy of the file. There are also tools included to help you cleanup unwanted files or folders, delete empty directories and find duplicate files. The script has a simple menu driven PowerShell GUI similar to what I did in a previous post. The Media Sync PowerShell script provides the following features:

  • COPY all photos and videos in a given folder structure (maintains original file in original location).
  • MOVE all photos and videos in a given folder structure (original file is renamed and moved).
  • Rename the photo or video based on the date the photo or video was taken.
  • Directory structure organized by year and month the photo or video was taken.
  • Ability to delete any empty folders in a given path, this will help with the cleanup process after you have moved photos and videos from the original location.
  • Remove all files based off a given file extension, this will help with the cleanup process after you have moved photos and videos from the original location.
  • Utilize Out-GridView to highlight and delete files or folders, this can be used to cleanup files of any file extension.
  • Find duplicate files in a given directory.
  • View files in a given directory via Out-GridView.

How to Use

DISCLAIMER: Use at your own risk. The script is safe but has the ability to delete files and folders so just be careful.

In the below video examples, I use PowerShell 7.1 with the Windows Terminal. There are no additional prerequisites that need to be met to run this script. I recommend that you setup a temporary test folder structure like I have in the video examples before running this script against all of your photos and videos. Much of the data is outputted via Out-GridView. If you want to select all the items in Out-GridView, you can use CTRL + A to select all. The code is located in my GitHub, please click on the below link to access it.

GitHub


1: COPY files and folders

The first item in the Media Sync script that we are going to look at is the COPY process. This process should be used if you want to maintain the original file and folder structure. The source directory will NOT be modified at all during this process. This results in the same outcome that would occur if you manually copied and pasted the files from the source to the destination directory. In the below video example, I show you the steps to take and the expected output when you choose 1 for the COPY process.


2: MOVE files and folders

The second item in the Media Sync script that we are going to look at is the MOVE process. This process should be used if you want to rename and move the original file. The source directory WILL be modified during this process. This results in the same outcome that would occur if you manually cut and pasted the files from the source to the destination directory. In the below video example, I show you the steps to take and the expected output when you choose 2 for the MOVE process.


3: CLEANUP files and folders

The third item in the Media Sync script that we are going to look at is the CLEANUP process. This process should be used if you need to cleanup files or folders after you conduct a MOVE process. After you conduct a MOVE process, you will most likely be left with unwanted files and folders. Utilizing one of the below options could help you in that cleanup process.

3:1 Remove files with given extension (manual input)

In the below video example, I show you the steps to take and the expected output when you choose 3:1 for the CLEANUP process to remove files with a given extension. In the example, I inputted the file extension of txt but you can use any file extension that you want to remove.

3:2 Delete all empty directories

In the below video example, I show you the steps to take and the expected output when you choose 3:2 for the CLEANUP process to delete all empty directories. The Out-GridView results will display all empty directories. If there are no empty directories then there will be no Out-GridView displayed.

3:3 Utilize Out-GridView to highlight and delete files or folders

In the below video example, I show you the steps to take and the expected output when you choose 3:3 for the CLEANUP process to utilize Out-GridView to highlight and delete files or folders.

3:4:1 Find duplicate files in a given directory (View all of the duplicate files detected)

Use this process to view the duplicate files before you take action on them. Think of this as a report of the duplicate files detected. If two files are identical, then they will have the same exact hash. The Out-GridView results will display the hash for the files detected as duplicates.

3:4:2 Find duplicate files in a given directory (Move files for ONE duplicate group at a time)

Use this process if you want to view the duplicate groups one at a time instead of all of the duplicate groups at once. If you have a large amount of duplicates this can be cumbersome to click through, but you may prefer it for smaller batches of files. If two files are identical, then they will have the same exact hash. The Out-GridView results will display the hash for the files detected as duplicates so that you can decide which files to move to the duplicates directory.

3:4:3 Find duplicate files in a given directory (Move files for ALL duplicate groups)

In the below video example, I show you the steps to take and the expected output when you choose 3:4:3 for the CLEANUP process to find duplicate files in a given directory by moving files for ALL duplicate groups at once. If two files are identical, then they will have the same exact hash. The Out-GridView results will display the hash for the files detected as duplicates so that you can decide which files to move to the duplicates directory. In the video example below, I select one file per hash group to be moved.

3:4:4 Find duplicate files in a given directory (Auto move files)

Use this process if you do not want to utilize Out-GridView to review the duplicate results and just want to auto move duplicate file(s) to the duplicates directory. This process is the fastest, but you have less control over the results because the script will auto select which files get moved to the duplicates directory. For example, if you have 3 files that are identical, then the script will move 2 of those files to the given duplicates directory and keep 1 in the original location.

3:5 View files in a directory

In the below video example, I show you the steps to take and the expected output when you choose 3:5 for the CLEANUP process to view files in a directory. Use this process if you simply want to view all the files and folders in a given directory. This process is just for reporting purposes.

That’s it for now, thanks for reading!


Check out my other blog posts:

NetNeighbor Watch: The PowerShell Alternative To Arpwatch

In this post, we are going to setup NetNeighbor Watch on a Raspberry Pi. NetNeighbor Watch can keep an eye on your network and send you an email when a new host is discovered. NetNeighbor Watch is done completely in PowerShell. The results are very similar to those of arpwatch. NetNeighbor Watch is for anyone…

Generate a Citrix Desktop Report Based on Active Directory Users

In this post, we are going to merge data from two different sources to generate a report that can provide insight into your Citrix environment. I will show you how to combine Active Directory data for the users in your domain with Citrix data. This report will provide you with the following knowledge: Users that…

Creating a PowerShell Module to Improve Your Code

Do you have PowerShell code that you reuse in your scripts over and over? Do you have server names hard coded in variables? Are you using a text file or CSV file to import server names? Do you find yourself only utilizing one server out of a cluster of servers to make your PowerShell commands?…

Generate a DHCP Report Via PowerShell

Today we are going to look at how to generate a DHCP scope statistics HTML report by using PowerShell. This report will give you one location to see all of your DHCP scope statistics across all of your Windows DHCP servers. It will dynamically pull the DHCP servers and associated DHCP scopes within your Active…

Increase VMware VM Disk Size with PowerShell

In this post, I will cover how to use PowerShell to increase the disk size of a Windows 10 VM running in a VMware vCenter environment. Automating simple but time consuming tasks like this can save precious time for your support staff or yourself. There are two parts to accomplishing this task; first we need…

Manage Citrix Tags with PowerShell

In this post, we are going to cover how to manage Citrix tags with PowerShell. Citrix Studio is a great tool, but it can be very time consuming especially if you have to do bulk tag actions. Citrix tags can be used in several methods, but this post is focused on desktop tagging. This post…

Create a Text Box to Accept User Input for PowerShell GUI

Do you have a PowerShell GUI that needs to accept text input? Maybe you want to be able to copy and paste a list of computers, ip addresses, user names or some other data. I will show you how to add a text box into your PowerShell GUI to handle that input. If you haven’t…

Utilizing PowerShell Out-GridView as a GUI Alternative

In my previous post, I showed how you can build a simple menu driven PowerShell GUI; check it out here. To further improve upon that simple GUI, we will go over how to use Out-GridView. Out-GridView is a built-in powershell cmdlet that sends the output from a given command to an interactive window. This post…

How to Create a Simple PowerShell GUI

Have you ever wanted to create a menu driven PowerShell GUI to conduct a series of automated tasks? You are in luck, because that is exactly what we are going to cover in this post. This very simple PowerShell GUI will help you easily distribute your code to other team members or maybe you just…

One thought on “Media Sync: Organize Your Photos and Videos with PowerShell

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s