Functions/Update-MyModuleManifest.ps1
function Update-MyModuleManifest { [CmdletBinding()] param ( [Parameter(Mandatory)] [ArgumentCompleter( { param ( $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters ) Get-ChildItem "$($env:USERPROFILE)\Git\$wordToComplete*" -Directory -Name | ForEach-Object { "`"$_`"" } } )] [string] $Module, [Parameter()] [ValidateSet("Minor", "Major")] [string] $VersionChange = "Minor" ) if (Test-Path $Module) { $ModuleFolders = Get-Item $Module } else { #Set-Location $MyModulePath $MyModulePath = "$([Environment]::GetFolderPath("MyDocuments"))\WindowsPowerShell\Modules" if ($Module) { $ModuleFolders = Get-ChildItem $MyModulePath -Directory -Exclude ".git" | Where-Object Name -EQ $Module } else { $ModuleFolders = Get-ChildItem $MyModulePath -Directory -Exclude ".git", "PackageManagement" } } foreach ($m in $ModuleFolders) { Write-Output "Updating module: $($m.BaseName)" $FunctionsToExport = (Get-ChildItem (Join-Path $m.FullName -ChildPath "Functions") -File).BaseName $VariablesToExport = @('absolutelynothing') if (Test-Path (Join-Path $m.FullName -ChildPath "Variables")) { $VariablesToExport = (Get-ChildItem (Join-Path $m.FullName -ChildPath "Variables")).BaseName } if (Test-Path (Join-Path $m.FullName -ChildPath "Other\RequiredModules.csv")) { $RequiredModules = Import-Csv (Join-Path $m.FullName -ChildPath "Other\RequiredModules.csv") | Select-Object -ExpandProperty Modulename } else { $RequiredModules = @() } if (Test-Path (Join-Path $m.FullName -ChildPath "Other\ModuleDescription.txt")) { $ModuleDescription = Get-Content (Join-Path $m.FullName -ChildPath "Other\ModuleDescription.txt") } else { $ModuleDescription = $m.BaseName } $ModuleInfo = Get-Module $m.FullName -ListAvailable if ($VersionChange -eq "Major") { $CurrentVersion = $ModuleInfo.Version.Major $NewVersion = $CurrentVersion + 1 $NewVersion = "$($NewVersion).0" } else { $CurrentVersion = $ModuleInfo.Version.Minor $NewVersion = $CurrentVersion + 1 $NewVersion = "$($ModuleInfo.Version.Major).$($NewVersion)" } $ModuleManifestParameters = @{ Path = (Join-Path $m.FullName -ChildPath ($m.BaseName + ".psd1")) RootModule = $m.BaseName + ".psm1" ModuleVersion = $NewVersion FunctionsToExport = $FunctionsToExport VariablesToExport = $VariablesToExport Copyright = "(c) $((Get-Date).Year) JT. All rights reserved." } if ($RequiredModules) { $ModuleManifestParameters.Add("RequiredModules", $RequiredModules) } if ($ModuleDescription) { $ModuleManifestParameters.Add("Description", $ModuleDescription) } #$ModuleManifestParameters if (Test-Path $ModuleManifestParameters.Path) { Update-ModuleManifest @ModuleManifestParameters } else { New-ModuleManifest @ModuleManifestParameters } } #return $ModuleFolders } |