Remove-Module
從目前的工作階段中移除模組。
語法
name
Remove-Module
[-Name] <String[]>
[-Force]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
FullyQualifiedName
Remove-Module
[-FullyQualifiedName] <ModuleSpecification[]>
[-Force]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
ModuleInfo
Remove-Module
[-ModuleInfo] <PSModuleInfo[]>
[-Force]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Description
Remove-Module Cmdlet 會從目前的工作階段中移除模組的成員,例如 Cmdlet 和函式。
如果模組包含程式集 (),.dll則程式集實現的所有成員都會被刪除,但不會卸載程式集。
此 Cmdlet 不會卸載模組,也不會從計算機中刪除它。 它只會影響目前的PowerShell會話。
範例
範例 1:移除模組
Remove-Module -Name "BitsTransfer"
此命令會從目前的會話中移除 BitsTransfer 模組。
範例 2:移除所有模組
Get-Module | Remove-Module
此命令會從目前的工作階段中移除所有模組。
範例 3:使用管線移除模組
"FileTransfer", "PSDiagnostics" | Remove-Module -Verbose
VERBOSE: Performing operation "Remove-Module" on Target "filetransfer (Path: 'C:\Windows\system32\WindowsPowerShell\v1.0\Modules\filetransfer\filetransfer.psd1')".
VERBOSE: Performing operation "Remove-Module" on Target "Microsoft.BackgroundIntelligentTransfer.Management (Path: 'C:\Windows\assembly\GAC_MSIL\Microsoft.BackgroundIntelligentTransfer.Management\1.0.0.0__31bf3856ad364e35\Microsoft.BackgroundIntelligentTransfe
r.Management.dll')".
VERBOSE: Performing operation "Remove-Module" on Target "psdiagnostics (Path: 'C:\Windows\system32\WindowsPowerShell\v1.0\Modules\psdiagnostics\psdiagnostics.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:\Windows\system32\WindowsPowerShell\v1.0\Modules\psdiagnostics\PSDiagnostics.psm1')".
此命令會從目前的會話中移除 BitsTransfer 和 PSDiagnostics 模組。
命令會使用管線運算子 (|) 將模組名稱傳送至 Remove-Module。 它會使用 Verbose 一般參數來取得已移除成員的詳細資訊。
詳細資訊 訊息會顯示已移除的專案。 訊息不同,因為 BitsTransfer 模組包含實作其 Cmdlet 的元件,以及具有其本身元件的巢狀模組。 PSDiagnostics 模組包含導出函式的模組腳本檔案(.psm1)。
範例 4:使用 ModuleInfo 移除模組
$a = Get-Module BitsTransfer
Remove-Module -ModuleInfo $a
此命令會使用 ModuleInfo 參數來移除 BitsTransfer 模組。
參數
-Confirm
在執行 Cmdlet 之前,提示您進行確認。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | False |
| 支援萬用字元: | False |
| 不要顯示: | False |
| 別名: | cf |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Force
表示此 Cmdlet 會移除唯讀模組。 根據預設,Remove-Module 只會移除讀寫模組。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-FullyQualifiedName
指定要移除之模組的完整名稱。
參數屬性
| 類型: | |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
FullyQualifiedName
| Position: | 0 |
| 必要: | True |
| 來自管線的值: | True |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-ModuleInfo
指定要移除的模組物件。 輸入包含模組物件 (PSModuleInfo) 的變數或獲取模組物件的命令(如 Get-Module 命令)。 您也可以使用管線將模組物件傳送至 Remove-Module。
參數屬性
| 類型: | |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
ModuleInfo
| Position: | 0 |
| 必要: | True |
| 來自管線的值: | True |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-Name
指定要移除的模組名稱。 允許使用通配符字元。 您也可以使用管線將名稱字串傳送至 Remove-Module。
參數屬性
| 類型: | String[] |
| 預設值: | None |
| 支援萬用字元: | True |
| 不要顯示: | False |
參數集
name
| Position: | 0 |
| 必要: | True |
| 來自管線的值: | True |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-WhatIf
顯示 Cmdlet 執行時會發生什麼事。 指令未執行。
參數屬性
| 類型: | SwitchParameter |
| 預設值: | False |
| 支援萬用字元: | False |
| 不要顯示: | False |
| 別名: | 無線 |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
CommonParameters
此 Cmdlet 支援一般參數:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 如需詳細資訊,請參閱 about_CommonParameters。
輸入
System.String, System.Management.Automation.PSModuleInfo
您可以將模組名稱與模組物件通過導管傳輸到 Remove-Module。
輸出
None
此 Cmdlet 不會產生任何輸出。
備註
刪除模組時,模組上將執行一個事件。 此事件允許模組對被刪除做出反應並執行一些清理,例如釋放資源。 範例:
$OnRemoveScript = {
# 執行清理
$cachedSessions |Remove-PSSession
}
$ExecutionContext.SessionState.Module.OnRemove += $OnRemoveScript
為了完全一致,對 PowerShell 進程的關閉做出反應也可能很有用:
Register-EngineEvent -SourceIdentifier ([System.Management.Automation.PsEngineEvent]::Exiting) -Action $OnRemoveScript