· Uwe Janke
Commands / Update-sqmModule

Update-sqmModule

sqmTool Config sqmSQLTool v1.0.0+ · Update ✓ -WhatIf supported
Updates sqmSQLTool source-aware: from the install source that was used last. Three sources are supported: PSGallery (Install-Module), GitHub (the release ZIP of the repository) and UNC / LocalDir (copying the files from a share or a folder).

Without parameters it calls Test-sqmModuleUpdate itself. If the last source is not reachable, that check falls back through PSGallery, GitHub and the configured update repository. With -UpdateInfo (the result of that check) it skips the check.

Version folders. If the module sits in a version folder (...\Modules\sqmSQLTool\1.9.140.0, the way Install-Module places it), the new version is not copied into it, because folder name and ModuleVersion would no longer match and PowerShell would not find the module. A sibling folder with the new version number is created and the old version stays untouched next to it. A backup is only made for a flat folder.

Rights. An AllUsers installation under Program Files needs administrator rights. The function checks that up front and stops with a warning instead of failing in the middle of copying. The new version applies from the next PowerShell session or after Import-Module sqmSQLTool -Force.

At module start the same function can run on its own: UpdateMode Prompt (default) offers a newer version, Auto installs it without asking, Off does not check.

Parameters

ParameterTypeRequiredDefaultNotes
-UpdateInfohashtableOptionalTest-sqmModuleUpdateResult of Test-sqmModuleUpdate (Source, Version, Path). Without it the check runs inside the function.
-CredentialPSCredentialOptional, Credentials for UNC shares.
-BackupswitchSwitch$trueBack up the module folder to %TEMP% before a file update. Not needed (and not done) for version folders.
-ForceswitchSwitch$falseUpdate even if no newer version was found.
-WhatIf / -ConfirmswitchOptional, Shows which source and target would be used.

Execution Flow

START Find the update without -UpdateInfo: Test-sqmModuleUpdate against the last used install source PSGallery, GitHub, UNC or LocalDir; no newer version and no -Force: nothing to do Module folder writable? NO Warning, stop run PowerShell as administrator YES Dispatch by source PSGallery: Install-Module -Force -AllowClobber (scope AllUsers or CurrentUser) GitHub: release ZIP sqmSQLTool-v<version>.zip, unpack, copy the files UNC / LocalDir: copy from the repository path Copy the files backup to %TEMP%\sqmSQLTool_Backup_<time> unless the module sits in a version folder unblock every file, take over a sqmSQLTool.site.json that lies above the source Report green line with the target; the new version applies from the next session or after Import-Module sqmSQLTool -Force END

Return value

No return object. The function writes status lines to the host (green: updated, gray: backup path, yellow: when the new version applies) and sets $env:SQMSQLTOOL_UPDATED to the new version (or unknown), which the GUI launcher and the start check use to reload the module.

SituationResult
No newer version and no -ForceMessage with the installed version, nothing changes.
Module folder not writableWarning that administrator rights are needed. Nothing is changed.
PSGallery update failsWarning with the reason; nothing else is tried.
UNC / LocalDir: no source known or not reachableWarning (no install source and no UpdateRepository set, or the path is unreachable).
Any error while copyingError "Update fehlgeschlagen" with the reason.

Defaults: the GitHub repository is JankeUwe/sqmSQLTool. For UNC sources the path comes from the check, from the stored install source or from the configured UpdateRepository.

Examples

Check the install source and install a newer version if there is one
Update-sqmModule
Show what would be done
Update-sqmModule -WhatIf
Reinstall the current version from the source
Update-sqmModule -Force
Check first, then update with the result
$info = Test-sqmModuleUpdate
if ($info) { Update-sqmModule -UpdateInfo $info }
Load the new version in the current session
Update-sqmModule
Import-Module sqmSQLTool -Force