Get file metadata from PowerShell script

Guilherme Matheus
2 min readSep 10, 2020

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.

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
cd C:\

# Load the PS1 file
.\Get-FileMetaDataReturnObject.ps1

# 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
$Metadata |
Export-Csv -Path $Dir -NoTypeInformation -Encoding UTF8

The scripts for this post can be found on my Github (@guimatheus92).

--

--

Guilherme Matheus

Mechanical Engineer Business Intelligence developer, passionate about technology, I have knowledge and experience to create a BI architecture and much more 📚.