New-ModulePSM1.ps1


Description

New-ModulePSM1 rebuilds the .psm1 file for a module by concatenating every script found in the module’s Public folder. Pass the root module path with -FilePath and the function removes the existing .psm1 before appending each script’s contents.

Usage examples

New-ModulePSM1 -FilePath 'C:\GitRepos\UserAdminModule'

The function expects helper variables (such as $path) to exist in scope; ensure the module’s structure matches the repository layout before running it to avoid deleting the wrong file.


Script

function New-ModulePSM1 {

    [CmdletBinding()]
    param (
        [Parameter( Mandatory = $true,
            ValueFromPipeline = $true,
            ValueFromPipelineByPropertyName = $true,
            HelpMessage = "Please enter the file path for the data input. The location should be an HR Share with restricted access."
        )]
        [string]
        $FilePath
    )

    $ModuleName = $path.Parent.name[0]

    $Scripts = Get-ChildItem -Path $FilePath\Public -File | Select-Object -Property FullName
    Remove-Item -Path $FilePath\$ModuleName.psm1

    foreach ( $Script in $Scripts) {
        $Content = Get-Content -Path "$($Script.fullname)"
        Add-Content -Path $FilePath\$ModuleName.psm1 -Value $Content
    }
}

Back to Top


Download

Please feel free to copy parts of the script or if you would like to download the entire script, simple click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.


Report Issues

You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.

Issue


Back to Top