Project

PSPublishModule

Build, test, version, sign, and publish PowerShell modules with reusable PowerForge pipelines.

Stars 48
Forks 16
PowerShell Gallery downloads 17,213
Release v3.0.186
Language: C# Updated: 2026-11-04
Command

Repair-ManagedModule

Module
PSPublishModule
Inputs
PSPublishModule.ModuleStateInventoryResult System.String[]
Outputs
PSPublishModule.ModuleStateWorkflowResult

Repairs and verifies installed PowerShell modules through the managed module-state engine.

Syntax

Repair-ManagedModule
[-AcceptLicense]
[-AllowClobber]
[-AllowConflict]
[-Cleanup <OldVersions>]
[-Credential <PSCredential>]
[-CredentialSecret <String>]
[-CredentialSecretFilePath <String>]
[-CredentialUserName <String>]
[-Family <MicrosoftGraph|Graph|Az|ExchangeOnline|Teams>]
[-Force]
[-IncludeAllUserProfiles]
[-IncludeLoaded]
[-InstallMissing]
[-Inventory <ModuleStateInventoryResult>]
[-InventoryPath <String>]
[-Latest]
[-MaintenanceReceiptPath <String[]>]
[-MinimumVersion <String>]
[-ModulePath <String[]>]
[-ModuleRoot <String>]
[[-Name] <String[]>]
[-Plan]
[-Prerelease]
[-ProfileName <String>]
[-Repository <String>]
[-RequiredResource <Object>]
[-RequiredResourceFile <String>]
[-Scope <CurrentUser|AllUsers>]
[-ShowSummary]
[-SkipDependencyCheck]
[-Transport <PrivateModule|ManagedModule|Auto>]
[-UserProfilePath <String[]>]
[-Version <String>]
[-VersionPolicy <String>]
[<CommonParameters>]
#
Parameter set: All Parameter Sets

Description

This command is the managed operator surface for module estate maintenance. It inventories installed modules, plans stale-version, receipt-drift, source, scope, family, and cleanup actions, and can apply the plan through the managed delivery engine.

PSResourceGet has no equivalent estate-repair command. Use the lifecycle cmdlets for one requested operation and this command when the desired outcome spans installed-state discovery, drift analysis, repair, and cleanup.

Repair keeps module copies in separate physical roots, PowerShell editions, scopes, and local user profiles independent. Missing modules require an explicit ModuleRoot or exactly one eligible scanned root; ambiguous destinations are reported and blocked. A single explicit UserProfilePath supplies the current PowerShell edition's standard CurrentUser root even when that root does not exist yet; it never overrides an AllUsers request. Explicit ModuleRoot and profile destinations are merged into supplied Inventory or InventoryPath artifacts and remain part of convergence scans. Module roots declared by maintenance receipts are merged the same way, including roots that do not exist until repair delivery creates them. A successfully enumerated explicit root replaces stale artifact rows and diagnostics for that root, even when the live root is empty.

Live apply performs delivery, inventories the same estate again, replans exact-path old-version cleanup from current state. Cleanup requires that refreshed plan to be error-free, preflights the complete exact-path removal set, validates loaded-module and dependency safety across relevant global/profile roots, and removes selected dependents before their selected dependencies. Current-runspace loaded modules are protected even when IncludeLoaded is not used for inventory output. A declined delivery or cleanup action is reported as skipped and cannot be reported as successful convergence. Repair performs a final live inventory and returns post-apply plan and convergence evidence after execution or a no-action apply. Operational failures remain visible in the typed result and are also written as nonterminating errors.

This is local-machine estate management suitable for workstations and servers, including service-account and multi-profile roots. It does not connect to or orchestrate remote computers; invoke it in each target session or through the operator's existing remoting/configuration system.

Examples

Preview latest-version repair for installed modules

Repair-ManagedModule -Latest -Repository PSGallery -Plan -ShowSummary

Preview version-coherence repair for Graph modules

Repair-ManagedModule -Family Graph -Repository PSGallery -Plan -ShowSummary

Preview baseline enforcement from a list of module names

Repair-ManagedModule -Name Company.Tools,Company.Web -InstallMissing -Latest -Repository PSGallery -Plan -ShowSummary

Preview baseline enforcement from a PSResourceGet-style resource file

Repair-ManagedModule -RequiredResourceFile .\required-resources.psd1 -Latest -Repository PSGallery -Plan -ShowSummary

Apply receipt-drift repair through a managed repository profile

Repair-ManagedModule -MaintenanceReceiptPath .\module-maintenance.json -ProfileName CompanyModules -AcceptLicense

Preview repair across Windows PowerShell and PowerShell 7 roots

Repair-ManagedModule -ModulePath $ps5Root,$ps7Root -Latest -Cleanup OldVersions -Repository PSGallery -Plan -ShowSummary

Preview modules installed for multiple local user profiles

Repair-ManagedModule -UserProfilePath C:\Users\Alice,C:\Users\Service.PowerShell -Name Company.* -Latest -Repository CompanyModules -Plan -ShowSummary

Apply safe old-version cleanup and verify convergence

Repair-ManagedModule -IncludeAllUserProfiles -Latest -Cleanup OldVersions -Repository CompanyModules -Confirm:$false -ShowSummary

Parameters

-AcceptLicense SwitchParameter optional
Accept package licenses when packages declare license acceptance is required.
-AllowClobber SwitchParameter optional
Allow managed delivery to overwrite exported command conflicts.
-AllowConflict SwitchParameter optional
Allow apply preparation to continue when the plan contains error findings.
-Cleanup String optional
Optional old-version cleanup. Live apply replans after delivery, requires an error-free refreshed estate, batch-preflights exact paths, and removes selected dependents before dependencies.
Possible values: OldVersions
-Credential PSCredential optional
Optional repository credential.
-CredentialSecret String optionalaliases: Password, Token
Optional repository credential secret.
-CredentialSecretFilePath String optionalaliases: CredentialPath, TokenPath
Optional path to a file containing the repository credential secret.
-CredentialUserName String optionalaliases: UserName
Optional repository credential username.
-Family String[] optional
Built-in module family policies to include in repair planning.
Possible values: MicrosoftGraph, Graph, Az, ExchangeOnline, Teams
-Force SwitchParameter optional
Force reinstall when repair selects the same installed version.
-IncludeAllUserProfiles SwitchParameter optional
Discover existing standard PowerShell module roots below the local profile container. Unix root sessions scan /home and retain /root; inaccessible optional profiles or roots are reported as warnings. Use UserProfilePath or ModulePath for redirected and custom layouts.
-IncludeLoaded SwitchParameter optional
Include modules loaded in the current runspace as inventory and plan evidence. Cleanup protects current-runspace modules regardless of this reporting option.
-InstallMissing SwitchParameter optional
Plan installs for literal names that are not present in the selected inventory.
-Inventory ModuleStateInventoryResult optionalpipeline: True (ByValue)
Existing inventory object. Explicit ModuleRoot and UserProfilePath destinations are merged into it and included in post-apply convergence scans.
-InventoryPath String optional
Path to a previously written inventory JSON artifact.
-Latest SwitchParameter optional
Plan latest-version repair/update delivery for selected installed modules.
-MaintenanceReceiptPath String[] optional
Optional module-state maintenance receipt artifacts used for drift checks. Receipt-declared module roots are inventoried and retained for post-apply convergence.
-MinimumVersion String optional
Minimum version used when repairing named modules.
-ModulePath String[] optional
Explicit required module roots to inventory. Missing or inaccessible roots block apply. When omitted, optional roots inherited together from the current process's PSModulePath are treated as one dependency-visibility context.
-ModuleRoot String optionalaliases: Path
Explicit physical module root used to narrow inventory selection and managed delivery. It also resolves missing-module destination ambiguity.
-Name String[] optionalposition: 0pipeline: True (ByPropertyName)aliases: ModuleName
Optional module names to repair. When omitted, all installed modules in scope are considered.
-Plan SwitchParameter optional
Return the full repair and cleanup plan without applying any actions.
-Prerelease SwitchParameter optionalaliases: AllowPrerelease
Include prerelease versions during managed delivery.
-ProfileName String optional
Saved repository profile used by managed delivery.
-Repository String optionalaliases: RepositoryUri, Source
Repository source or registered repository name used by managed delivery.
-RequiredResource Object optional
PSResourceGet-style required resource map used as desired module state.
-RequiredResourceFile String optional
Path to a PowerShell data file containing a PSResourceGet-style required resource map.
-Scope String optional
Target installation scope used when selecting installed baseline modules.
Possible values: CurrentUser, AllUsers
-ShowSummary SwitchParameter optional
Write a compact Spectre.Console summary.
-SkipDependencyCheck SwitchParameter optionalaliases: SkipDependenciesCheck
Skip installing dependencies declared by repaired packages.
-Transport ModuleStateDeliveryTransport optional
Delivery transport used for install/update repair actions.
Possible values: PrivateModule, ManagedModule, Auto
-UserProfilePath String[] optional
Explicit user profile home directories whose platform-standard module roots are inventoried. Existing roots are required and block repair when inaccessible; a missing current-edition root remains a creatable destination. One explicit profile provides that CurrentUser destination for missing modules, but never overrides AllUsers scope.
-Version String optionalaliases: RequiredVersion
Exact required version used when repairing named modules.
-VersionPolicy String optional
NuGet-style version range policy used when repairing named modules.

Common Parameters

This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.

For more information, see about_CommonParameters.

Outputs

PSPublishModule.ModuleStateWorkflowResult: PowerShell-facing result for a complete module-state management workflow.