Skip to content

Instantly share code, notes, and snippets.

@Nillth
Created November 11, 2020 06:55
Show Gist options
  • Save Nillth/98fab98bed708e12b17b1a7dc4760a12 to your computer and use it in GitHub Desktop.
Save Nillth/98fab98bed708e12b17b1a7dc4760a12 to your computer and use it in GitHub Desktop.
Merges all the Files in a PowerShell Script Module into a single file
$Modules = "Qlik-CLI"
foreach ($modulename in $Modules) {
$PSModule = Get-module -Name $modulename -ListAvailable | Sort-Object -property version | select -First 1
$PSModuleData = Import-LocalizedData -BaseDirectory $PSModule.ModuleBase -FileName ([system.io.fileinfo]$PSModule.Path).name
$ResourceFiles = $PSModuleData.NestedModules + $PSModuleData.RootModule + $PSModuleData.ModuleToProcess | select -Unique
$ConsolidatedModules = foreach ($Module in $ResourceFiles) {
[system.io.fileinfo]$FilePath = Join-Path -Path $PSModule.ModuleBase -ChildPath $Module -Resolve
$FileContent = Get-Content $FilePath.FullName -Raw
@"
#region Source: $($Module)
$FileContent
#endregion Source: $($Module)
"@
}
$OutFile = "$($PSModule.Name)_$($PSModule.Version).ps1"
$ConsolidatedModules | out-file -Encoding utf8 -FilePath $OutFile
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment