刷新 Powershell 实例/会话
Refresh Powershell Instance / Session
首先我要声明我不是专家级的 Powershell 用户,所以我可能用错了方法。
我有一个我经常使用的模块,我经常更新/调整它。如果重要的话,它存储在 C:\Users\-user-\Documents\WindowsPowerShell\Modules
中。
目前,如果我想访问新的/更新的方法,我必须关闭 powershell window 并重新打开一个新的 - 即使我在与我相同的 window 中执行导入正在执行命令。
我试过 . $profile
但这没有任何效果。我需要将模块添加到配置文件吗?
您可以简单地卸载模块,然后重新加载。
正如我们在微软的文档中看到的那样:
删除模块
The Remove-Module cmdlet removes the members of a module, such as
cmdlets and functions, from the current session.
导入模块
The Import-Module cmdlet adds one or more modules to the current
session. The modules that you import must be installed on the local
computer or a remote computer.
下面是一个代码示例:
# Unload the Module
PS > Remove-Module myModule -Force
# Load it again
PS > Import-Module myModule
删除和添加模块的替代方法是 Import-Module myModule -Force
:
-Force [< SwitchParameter >]
Indicates that this cmdlet re-imports a module and its members, even if the module or its members
have an access mode of read-only.
首先我要声明我不是专家级的 Powershell 用户,所以我可能用错了方法。
我有一个我经常使用的模块,我经常更新/调整它。如果重要的话,它存储在 C:\Users\-user-\Documents\WindowsPowerShell\Modules
中。
目前,如果我想访问新的/更新的方法,我必须关闭 powershell window 并重新打开一个新的 - 即使我在与我相同的 window 中执行导入正在执行命令。
我试过 . $profile
但这没有任何效果。我需要将模块添加到配置文件吗?
您可以简单地卸载模块,然后重新加载。
正如我们在微软的文档中看到的那样:
删除模块
The Remove-Module cmdlet removes the members of a module, such as cmdlets and functions, from the current session.
导入模块
The Import-Module cmdlet adds one or more modules to the current session. The modules that you import must be installed on the local computer or a remote computer.
下面是一个代码示例:
# Unload the Module
PS > Remove-Module myModule -Force
# Load it again
PS > Import-Module myModule
删除和添加模块的替代方法是 Import-Module myModule -Force
:
-Force [< SwitchParameter >]
Indicates that this cmdlet re-imports a module and its members, even if the module or its members have an access mode of read-only.