Powershell Script to Auto Import .REG files in Current DirectoryA simple PowerShell script which will auto import .REG files in the current directory. Useful for automating deployments or machine setup.
I frequently need to import a bunch of Registry settings stored in an 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.
#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
}