简体   繁体   English

PowerShell 如何更改用户默认的 PSModulePath

[英]PowerShell how to change the users default PSModulePath

My work network folder creates a problem with PowerShell Module Paths on my work laptop.我的工作网络文件夹在我的工作笔记本电脑上创建了 PowerShell 模块路径问题。 They use caching of the home folder;他们使用主文件夹的缓存; while on the work network, my actual files are synced to my local disk so that I can access offline, and any changes I make offline are synced back up when I am back on the corporate network.在工作网络上,我的实际文件会同步到我的本地磁盘,以便我可以离线访问,当我回到公司网络时,我离线所做的任何更改都会同步备份。 In $env:PSModulePath, I have在 $env:PSModulePath 中,我有

\\ad.xxx.net\WPS\XX\P\UD\200024\UserName\Home\My Documents\WindowsPowerShell\Modules

When I connected to the corporate network, this works fine, but when I am offline, starting PowerShell always attempts to connect via the UNC path, which fails until it times out, so starting a PowerShell console takes more than 20 seconds every time.当我连接到公司网络时,这工作正常,但是当我离线时,启动 PowerShell总是尝试通过 UNC 路径进行连接,该路径失败直到超时,因此每次启动 PowerShell 控制台需要 20 多秒。

To try and fix this, I have changed PSModulePath in HKCU\\Environment to an equivalent of the above on the C: drive ( C:\\Users\\UserName\\Documents\\WindowsPowerShell\\Modules ) but this fails and everytime a PowerShell console starts, it always tries to access to find that Module path via the network and always times out / fails / 20+ second startup time.为了尝试解决此问题,我已将HKCU\\Environment中的PSModulePath更改为 C: 驱动器( C:\\Users\\UserName\\Documents\\WindowsPowerShell\\Modules )上的等效项,但是这失败了,每次 PowerShell 控制台启动时,它总是尝试通过网络访问以找到该模块路径,并且总是超时/失败/20 秒以上的启动时间。

Is there a way that I can remove the default user Module path, or redirect to the C: drive to circumvent this issue?有没有办法可以删除默认的用户模块路径,或重定向到 C: 驱动器来规避此问题?

You can change the PSModulePath using this(completely new value)您可以使用此(全新的值)更改 PSModulePath

[Environment]::SetEnvironmentVariable("PSModulePath",[System.IO.Path]::PathSeparator + "Your Path", "PC name")

Or this(Keeping the old value):或者这个(保持旧值):

$CurrentValue = [Environment]::GetEnvironmentVariable("PSModulePath", "PC name")
[Environment]::SetEnvironmentVariable("PSModulePath", $CurrentValue + [System.IO.Path]::PathSeparator + "Your path", "PC name")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM