如何在系统启动时导入PowerShell模块?

如何在系统启动时导入PowerShell模块?,powershell,module,startup,import-module,Powershell,Module,Startup,Import Module,我希望在系统启动时导入自定义PowerShell模块(.dll) 有一种方法可以在$profile文件中写入导入模块路径。因此,每当我们启动PowerShell时,它都会被导入。但是,如果其他程序使用自定义模块发出的任何命令调用powershell.exe,则它可能不会使用配置文件 是否有任何方法可以导入自定义模块,以便任何用户/程序都可以使用其中的命令let?可能是因为您没有填写正确的配置文件。看看: $profile.AllUsersAllHosts C:\Windows\System32\

我希望在系统启动时导入自定义PowerShell模块(.dll)

有一种方法可以在$profile文件中写入
导入模块路径
。因此,每当我们启动PowerShell时,它都会被导入。但是,如果其他程序使用自定义模块发出的任何命令调用powershell.exe,则它可能不会使用配置文件


是否有任何方法可以导入自定义模块,以便任何用户/程序都可以使用其中的命令let?

可能是因为您没有填写正确的配置文件。看看:

$profile.AllUsersAllHosts
C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
而不是:

$profile.AllUsersCurrentHost
C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1

$profile.CurrentUserAllHosts
C:\Users\JPB\Documents\WindowsPowerShell\profile.ps1

$profile.CurrentUserCurrentHost
C:\Users\JPB\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

您可以将其导入其中一个机器配置文件,例如CurrentUserAllHosts。有关更多信息,请参阅关于配置文件帮助主题。

谢谢JP。我知道你提到的文件不存在。我需要创建它们吗?是的,您必须以管理员身份登录并创建所需的。