Register-File: Using regsvr32.exe with PowerShell

Adam Bertram

Adam Bertram

Read more posts by this author.

This article will discuss what Register-File using regsvr32.exe. I’m lazy as any good admin should be. I don’t like having to search for information when I don’t have to. I especially don’t like searching for “that one EXE file I knew was here somewhere” or what syntax to use for that EXE file.

This is why I create simple, little functions that may seem tedious and unnecessary at first. I create these functions to fit my brain. Whenever I need to do something I immediately think “What cmdlet would I look for?” and if it doesn’t exist I create it. Even if it’s to execute a 1-line EXE file.

In this instance, I have the function called Register-File. The only real thing this does is execute regsvr32.exe /s $SomeFile and ensure $SomeFile exists. It may sound foolish but I can never seem to remember the exact syntax plus I always seem to fat-finger the file somehow, watch it error and try again.

All I have to do now is type Register-File with the file name and be done. Register-File is a lot easier to remember that regsvr32.exe right?

P.S. Another good way to prevent having to remember syntax is PowerShell aliases. Perhaps I’ll leave that one for another post.

function Register-File {
                A function that uses the utility regsvr32.exe utility to register a file
    	    .PARAMETER FilePath
                The file path
    param (
        [ValidateScript({ Test-Path -Path $_ -PathType 'Leaf' })]
    process {
        try {
            $Result = Start-Process -FilePath 'regsvr32.exe' -Args "/s $FilePath" -Wait -NoNewWindow -PassThru
		} catch {
        	Write-Error $_.Exception.Message $false

Subscribe to Adam the Automator

Get the latest posts delivered right to your inbox

Looks like you're offline!