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 /s, 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

Join the Jar Tippers on Patreon

It takes a lot of time to write detailed blog posts like this one. In a single-income family, this blog is one way I depend on to keep the lights on. I'd be eternally grateful if you could become a Patreon patron today!

Become a Patron!