In this post, I will show you how to get a file’s metadata inside the Windows system using a PowerShell script.
A file’s metadata can have the name, size, creation date, file format, directory the file is located, etc.
This information can be important if you are working with photos for example, where you can store the photos in a database with your information.
So first, we must download the powershell script that has the function to access this information from a file through the link below.
get file meta data function
This script uses the Shell.Application object to get file metadata. It returns the metadata as a custom PowerShell…
After downloading the PS1 file (powershell script), we can use the script to get the metadata for each file within a previously defined directory.
# To execute the script without agreeing with the execution policy
Set-ExecutionPolicy Bypass -Scope Process
# Defines the directory where the PS1 file will be, which has the function to discover the file metadata
# Load the PS1 file
# Import the PS1 file to access the functions
Import-module .\Get-FileMetaDataReturnObject.ps1 -Force
# Defines the directory where the files will be, to get their metadata
$FilePath = "C:\"
# Defines the directory and name of the file to be exported to the CSV file
$Dir = "C:\METADATA_CSV.csv"
# Loads photo metadata into the variable
$Metadata = Get-FileMetaData -folder $FilePath
# Exports the metadata of the files found in the directory, to a CSV file
Export-Csv -Path $Dir -NoTypeInformation -Encoding UTF8
The scripts for this post can be found on my Github (@guimatheus92).