Reputation: 81
I am trying to remove module Microsoft.Powershell.Utility from powershell through Remove-Module. The command succeeds but after that I am still able to use commands from that module, like Format-Hex. What am I missing? I attach a screenshot that shows the behavior
My environment is a Windows 10 Home.
Upvotes: 1
Views: 1199
Reputation: 438398
As Ben notes, unloading module Microsoft.Powershell.Utility
is ill-advised, because it contains many important cmdlets (see list below).
The reason that the module's commands automatically reappear is PowerShell's module auto-loading feature, which loads (imports) modules located in the directories listed in $env:PSModulePath
automatically, on demand.
You can prevent auto-loading by setting the $PSModuleAutoLoadingPreference
preference variable to None
, for instance.
Note that in the case of name conflicts - if multiple modules contain commands of the same name:
Whatever module was imported last "wins" - unless you used Import-Module -NoClobber
, in which case importing fails.
You can use also selectively import from a module, using the member-type-specific -Cmdlet
, -Function
, -Alias
and -Variable
parameters.
You can use Import-Module -Prefix
to attach a prefix to the imported members in order to make their names unique, which in the case of cmdlets and functions goes before the noun part; e.g., Import-Module -Prefix Bar ...
would rename a cmdlet named Get-Foo
to Get-BarFoo
).
Finally, if there are duplicate names, you can disambiguate by prepending the module name to the member name in the form <ModuleName>\<command>
; e.g., Microsoft.PowerShell.Utility\Format-Hex
.
The list of cmdlets that come with module Microsoft.Powershell.Utility
, as of Windows PowerShell 5.1:
PS> (Get-Command -Module Microsoft.Powershell.Utility).Name
ConvertFrom-SddlString
Format-Hex
Get-FileHash
Import-PowerShellDataFile
New-Guid
New-TemporaryFile
Add-Member
Add-Type
Clear-Variable
Compare-Object
ConvertFrom-Csv
ConvertFrom-Json
ConvertFrom-String
ConvertFrom-StringData
Convert-String
ConvertTo-Csv
ConvertTo-Html
ConvertTo-Json
ConvertTo-Xml
Debug-Runspace
Disable-PSBreakpoint
Disable-RunspaceDebug
Enable-PSBreakpoint
Enable-RunspaceDebug
Export-Alias
Export-Clixml
Export-Csv
Export-FormatData
Export-PSSession
Format-Custom
Format-List
Format-Table
Format-Wide
Get-Alias
Get-Culture
Get-Date
Get-Event
Get-EventSubscriber
Get-FormatData
Get-Host
Get-Member
Get-PSBreakpoint
Get-PSCallStack
Get-Random
Get-Runspace
Get-RunspaceDebug
Get-TraceSource
Get-TypeData
Get-UICulture
Get-Unique
Get-Variable
Group-Object
Import-Alias
Import-Clixml
Import-Csv
Import-LocalizedData
Import-PSSession
Invoke-Expression
Invoke-RestMethod
Invoke-WebRequest
Measure-Command
Measure-Object
New-Alias
New-Event
New-Object
New-TimeSpan
New-Variable
Out-File
Out-GridView
Out-Printer
Out-String
Read-Host
Register-EngineEvent
Register-ObjectEvent
Remove-Event
Remove-PSBreakpoint
Remove-TypeData
Remove-Variable
Select-Object
Select-String
Select-Xml
Send-MailMessage
Set-Alias
Set-Date
Set-PSBreakpoint
Set-TraceSource
Set-Variable
Show-Command
Sort-Object
Start-Sleep
Tee-Object
Trace-Command
Unblock-File
Unregister-Event
Update-FormatData
Update-List
Update-TypeData
Wait-Debugger
Wait-Event
Write-Debug
Write-Error
Write-Host
Write-Information
Write-Output
Write-Progress
Write-Verbose
Write-Warning
Upvotes: 6