未永久加载的模块

Ant*_*ric 2 powershell module

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

示例图像在这里

Mat*_*att 5

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

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

注意:上面的链接是基于 cmd 的环境变量,不能直接在 PowerShell 中工作。在 PowerShell 中,您将使用 provider $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. 
Run Code Online (Sandbox Code Playgroud)

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

而作为CB。说:

从 Windows PowerShell 3.0 开始,当在命令中使用模块中的任何 cmdlet 或函数时,将自动导入模块。此功能适用于包含在PSModulePath环境变量值中的目录中的任何模块。

  • 只是一个辅助节点:从 Windows PowerShell 3.0 开始,当在命令中使用模块中的任何 cmdlet 或函数时,将自动导入模块。此功能适用于包含在 PSModulePath 环境变量值中的目录中的任何模块。 (2认同)