PowerShell Module Deployment - Converting PS1 files to PSM1

When writing modules we need our functions to be in psm1 files instead of the usual PowerShell ps1 files. While the only difference between the two is the extension, it is far more cumbersome to develop directly with the psm1 files as they cannot be directly executed.

A simple and convenient workaround is to develop with ps1 files but convert them to psm1 during the build process.

This is easy to accomplish when using a deployment tool such as PSDeploy. Below is a sample deployment file to build to the local modules directory.

$DstPath = 'C:\Program Files\WindowsPowerShell\Modules\ModuleName'

Deploy 'Deploy ModuleName to Local Modules' {

    By Filesystem {
        FromSource "src"
        To $DstPath
        WithOptions @{
            Mirror = $True
        }    
    }

    # Here we rename the ps1 files to psm1
    By Task RenamePs1FilesToPsm1 {
        Get-ChildItem $DstPath -Filter "*.ps1" | Rename-Item -NewName {$_.BaseName + ".psm1"}
    }
}

If you enjoyed this post consider sharing it on , , , or , and .