Remove-Module

Removes modules from the current session.
Remove-Module [-ModuleInfo*] <PSModuleInfo[]> [-Force] [-Confirm] [-WhatIf] [<CommonParameters>]
Remove-Module [-Name*] <String[]> [-Force] [-Confirm] [-WhatIf] [<CommonParameters>]
Remove-Module [-FullyQualifiedName*] <ModuleSpecification[]> [-Confirm] [-WhatIf] [<CommonParameters>]

The Remove-Module cmdlet removes the members of a module, such as cmdlets and functions, from the current session.

If the module includes an assembly (.dll), all members that are implemented by the assembly are removed, but the assembly is not unloaded.

This cmdlet does not uninstall the module or delete it from the computer. It affects only the current Windows PowerShell session.

Parameters
-Force [<SwitchParameter>]

Indicates that this cmdlet removes read-only modules. By default, Remove-Module removes only read-write modules.

The ReadOnly and ReadWrite values are stored in AccessMode property of a module.

-FullyQualifiedName <ModuleSpecification[]>

  • This value is required
  • Accepts pipeline input ByValue

Specifies the fully qualified names of modules to remove.

-ModuleInfo <PSModuleInfo[]>

  • This value is required
  • Default value is None
  • Accepts pipeline input ByValue

Specifies the module objects to remove. Enter a variable that contains a module object (PSModuleInfo) or a command that gets a module object, such as a Get-Module command. You can also pipe module objects to Remove-Module.

-Name <String[]>

  • This value is required
  • Accepts pipeline input ByValue

Specifies the names of modules to remove. Wildcard characters are permitted. You can also pipe name strings to Remove-Module.

-Confirm [<SwitchParameter>]

  • Default value is false

Prompts you for confirmation before running the cmdlet.Prompts you for confirmation before running the cmdlet.

-WhatIf [<SwitchParameter>]

  • Default value is false

Shows what would happen if the cmdlet runs. The cmdlet is not run.Shows what would happen if the cmdlet runs. The cmdlet is not run.

<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,ErrorAction, ErrorVariable, WarningAction, WarningVariable,OutBuffer, PipelineVariable, and OutVariable.

Inputs

System.String, System.Management.Automation.PSModuleInfo

You can pipe module names and module objects to Remove-Module.

Outputs

None

This cmdlet does not generate any output.

Examples
  1. Remove a module:
    PS C:> Remove-Module -Name "BitsTransfer"
    

    This command removes the BitsTransfer module from the current session.

  2. Remove all modules:
    PS C:> Get-Module | Remove-Module
    

    This command removes all modules from the current session.

  3. Remove modules by using the pipeline:
    PS C:> "FileTransfer", "PSDiagnostics" | Remove-Module -Verbose
    VERBOSE: Performing operation "Remove-Module" on Target "filetransfer (Path: 'C:Windowssystem32WindowsPowerShellv1.0Modulesfiletransferfiletransfer.psd1')". VERBOSE: Performing operation "Remove-Module" on Target "Microsoft.BackgroundIntelligentTransfer.Management (Path: 'C:WindowsassemblyGAC_MSILMicrosoft.BackgroundIntelligentTransfer.Management1.0.0.0__31bf3856ad364e35Microsof
    t.BackgroundIntelligentTransfe
    r.Management.dll')".
    VERBOSE: Performing operation "Remove-Module" on Target "psdiagnostics (Path: 'C:Windowssystem32WindowsPowerShellv1.0Modulespsdiagnosticspsdiagnostics.psd1')". VERBOSE: Removing imported function 'Start-Trace'. VERBOSE: Removing imported function 'Stop-Trace'. VERBOSE: Removing imported function 'Enable-WSManTrace'. VERBOSE: Removing imported function 'Disable-WSManTrace'. VERBOSE: Removing imported function 'Enable-PSWSManCombinedTrace'. VERBOSE: Removing imported function 'Disable-PSWSManCombinedTrace'. VERBOSE: Removing imported function 'Set-LogProperties'. VERBOSE: Removing imported function 'Get-LogProperties'. VERBOSE: Removing imported function 'Enable-PSTrace'. VERBOSE: Removing imported function 'Disable-PSTrace'. VERBOSE: Performing operation "Remove-Module" on Target "PSDiagnostics (Path: 'C:Windowssystem32WindowsPowerShellv1.0ModulespsdiagnosticsPSDiagnostics.psm1')".
    

    This command removes the BitsTransfer and PSDiagnostics modules from the current session.

    The command uses a pipeline operator (|) to send the module names to Remove-Module. It uses the Verbose common parameter to get detailed information about the members that are removed.

    The Verbose messages show the items that are removed. The messages differ because the BitsTransfer module includes an assembly that implements its cmdlets and a nested module with its own assembly. The PSDiagnostics module includes a module script file (.psm1) that exports functions.

  4. Remove a module by using ModuleInfo:
    PS C:> $a = Get-Module BitsTransfer
    PS C:>  Remove-Module -ModuleInfo $a
    

    This command uses the ModuleInfo parameter to remove the BitsTransfer module.

Related Links

Get-Module
Import-Module