從目前的工作階段移除模組。

語法

Remove-Module [-ModuleInfo] <PSModuleInfo[]> [-Force] [-Confirm] [-WhatIf] [<CommonParameters>]

Remove-Module [-Name] <string[]> [-Force] [-Confirm] [-WhatIf] [<CommonParameters>]

描述

Remove-Module Cmdlet 會從目前的工作階段中移除模組的成員。

如果模組包含組件 (.dll),則此 Cmdlet 會移除組件所實作的所有成員,但不會卸載組件。

參數

-Force

移除模組,即使這些模組的存取模式是唯讀也一樣。

必要?

false

位置?

named

預設值

接受管線輸入?

false

接受萬用字元?

false

-ModuleInfo <PSModuleInfo[]>

指定要移除的模組物件。請輸入包含模組物件 (PSModuleInfo) 的變數,或者輸入可取得模組物件的命令,例如 Get-Module 命令。您也可以經由管道將模組物件輸出至 Remove-Module。

必要?

true

位置?

1

預設值

接受管線輸入?

true (ByValue)

接受萬用字元?

false

-Name <string[]>

指定要移除的模組名稱。允許使用萬用字元。您也可以經由管道將名稱字串輸出至 Remove-Module。

必要?

true

位置?

1

預設值

接受管線輸入?

true (ByValue)

接受萬用字元?

true

-Confirm

在執行命令前先提示確認。

必要?

false

位置?

named

預設值

接受管線輸入?

false

接受萬用字元?

false

-WhatIf

說明執行命令時將會發生何種情況,但不會實際執行命令。

必要?

false

位置?

named

預設值

接受管線輸入?

false

接受萬用字元?

false

<CommonParameters>

這個 Cmdlet 支援一般參數:-Verbose、-Debug、-ErrorAction、-ErrorVariable、-OutBuffer 和 -OutVariable。如需詳細資訊,請參閱 about_Commonparameters.

輸入和輸出

輸入型別是可經由管道輸出至 Cmdlet 的物件型別。傳回型別則是 Cmdlet 所傳回的物件型別。

輸入

System.String 或 System.Management.Automation.PSModuleInfo

您可以經由管道將模組名稱 (字串) 和模組物件輸出至 Remove-Module。

輸出

None

Remove-Module 不會產生任何輸出。

附註

您也可以利用 Remove-Module 的別名 "rmo" 來表示此 Cmdlet。如需詳細資訊,請參閱 about_Aliases。

範例 1

C:\PS>remove-module -name BitsTransfer

描述
-----------
這個命令會從目前的工作階段中移除 BitsTransfer 模組。






範例 2

C:\PS>get-module | remove-module

描述
-----------
這個命令會從目前的工作階段移除所有的模組。






範例 3

C:\PS>"FileTransfer", "PSDiagnostics" | remove-module -verbose

VERBOSE: Performing operation "Remove-Module" on Target "filetransfer (Path: 'C:\Windows\system32\WindowsPowerShell\v1.0\Modules\f
iletransfer\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')".

描述
-----------
這個命令會從目前的工作階段移除 FileTransfer 和 PSDiagnostics 模組。

這個命令會使用管線運算子 (|) 將模組名稱傳送至 Remove-Module。它會使用 Verbose 一般參數來取得移除之成員的詳細資訊。

「詳細訊息」會顯示移除的項目。這些訊息各不相同,因為 BitsTransfer 模組包含一個實作其 Cmdlet 的組件,以及一個具有其專屬組件的巢狀模組。PSDiagnostics 模組包含可匯出函數的模組指令碼檔案 (.psm1)。






範例 4

C:\PS>$a = get-module BitsTransfer

C:\PS> remove-module -moduleInfo $a

描述
-----------
這個命令會使用 ModuleInfo 參數來移除 BitsTransfer 模組。






請參閱




目錄