Today I had to create the manifest for several modules in one go. We had more than 10 modules (.psm1), each one in its own folder, and I needed to add a manifest to them so I could set the company of each module. Thanks to the PowerShell pipeline, I didn’t have to work very hard to get it done:
ls *.psm1 -Recurse | ForEach-Object {
$manifestFileName = $_.BaseName + ".psd1"
$manifestPath = Join-Path $_.Directory $manifestFileName
$companyConstant = "AnyCompany"
New-ModuleManifest -Path $manifestPath -RootModule $_.Name -Author $companyConstant -CompanyName $companyConstant -Copyright $companyConstant -FileList @($_.Name)
Write-Host $manifestPath
}
It’s a silly script, nothing mysterious about it, but I’m writing it down here for the future. The reason I needed this was so I could later unload all the loaded modules from this company in one go. That’s pretty easy too:
Get-module | Where-Object { $_.CompanyName -eq "AnyCompany" } | Remove-Module