未永久加载的模块

Modules not permanently loaded

我正在尝试 运行 使用 Start-BitsTransfer 的脚本。但是,每当我打开 Powershell 时,我每次都必须重新安装 BitsTransfer 模块。这也意味着我不能 运行 将 Powershell 调用到 运行 命令的脚本,因为模块认为它没有安装。

如果您希望每次都加载该模块,只需将该行 import-module BitsTransfer 放入其中一个 PowerShell 配置文件中。来自 TechNet

  • %windir%\system32\Windows­PowerShell\v1.0\profile.ps1 这适用于计算机的所有用户和所有 shells。
  • %windir%\system32\Windows­PowerShell\v1.0\Microsoft.Power­Shell_profile.ps1 这适用于计算机的所有用户,但仅适用于 Microsoft.PowerShell shell.
  • %UserProfile%\Documents\Windows­PowerShell\profile.ps1 这仅适用于当前用户和所有 shells。
  • %UserProfile%\Documents\WindowsPowerShell\Micro­soft.PowerShell_profile.ps1 这仅适用于当前用户并且仅适用于 Microsoft.PowerShell shell.

注意:以上链接是基于cmd的环境变量,不能直接在PowerShell中运行。在 PowerShell 中,您将使用提供程序 $env。例如:

$path = "$($env:windir)\system32\Windows­PowerShell\v1.0\profile.ps1"
# Assuming the directory '$($env:windir)\system32\Windows­PowerShell\v1.0' exists...
"Import-Module BitsTransfer" | Set-Content $path -Force
# This will OVERWRITE anything already there. This is just an example for reference. 

这不是安装的情况.....只是需要导入。我对 ActiveDirectory 模块做同样的事情。

正如 CB. 所说:

Beginning in Windows PowerShell 3.0, modules are imported automatically when any cmdlet or function in the module is used in a command. This feature works on any module in a directory that this included in the value of the PSModulePath environment variable.