Powershell Script to Auto Import .REG files in Current Directory

Published October 6, 2017 by .

A sinple Powershell script which will auto import .REG files in the current directory. Useful for automating deployments or machine setup.

Powershell Script to Auto Import .REG files in Current Directory

I frequently need to import a bunch of Registry settings stored in individual .REG files. These are for common machine setup tasks like adding scheduler entries, setting some default Windows settings, adding missing screen resolutions to Surface Book, removing library folders from Explorer and so on.

I could merge all of them into a single .REG file, but that introduces other problems including maintainability.

Instead I use a Powershell script which will iterate over all the .REG files in the current directory and import each one it finds.

powershell
#Grab current directory
$oInvocation = (Get-Variable MyInvocation).Value
$sCurrentDirectory = Split-Path $oInvocation.MyCommand.Path

#Grab all .reg and pipe it into a reg import command
Get-ChildItem $sCurrentDirectory -Filter "install.exe" -Recurse | 
foreach{
 Start-Process -FilePath "C:\windows\system32\cmd.exe" -WindowStyle Minimized `
 -ArgumentList @('/C REG IMPORT "' + $_.FullName + '"') -Wait
}
Comments

My website and its content are free to use without the clutter of adverts, tracking cookies, marketing messages or anything else like that. If you enjoyed reading this article, or it helped you in some way, all I ask in return is you leave a comment below or share this page with your friends. Thank you.

There are no comments yet. Why not get the discussion started?

We respect your privacy, and will not make your email public. Hashed email address may be checked against Gravatar service to retrieve avatars. This site uses Akismet to reduce spam. Learn how your comment data is processed.