gpt4 book ai didi

powershell - 在 powershell 中安装永久驱动器

转载 作者:行者123 更新时间:2023-12-02 23:54:42 25 4
gpt4 key购买 nike

是否可以在 powershell 中永久安装驱动器?即使在系统重启之后?

当我使用 New-PSDrive -Persist(当然还有所有其他必需的参数)时,它仅适用于当前的 Windows session 。我用的是 PS 5.1

我可以在文件资源管理器中看到该驱动器,它在系统中是持久的,但我从 Powershell ISE 中看不到它,即使由管理员运行也是如此。当我需要处理脚本时,我必须使用 New-PSDrive 才能从网络驱动器加载脚本。每当我重新启动计算机时,再一次无法从 ISE 看到该驱动器。不得不一直一次又一次地这样做有点烦人。

最佳答案

您对 -Persist 开关的理解不正确。如 the help 中所述, 请确保您指定的是全局范围。

New-PSDrive -Name 'X' -PSProvider 'FileSystem' -Root '\\share\C$' -Scope 'Global' -Persist

-Persist [<SwitchParameter>]

Indicates that this cmdlet creates a Windows mapped network drive. Mapped network drives are saved in Windows on the local computer. They are persistent, not session-specific, and can be viewed and managed in File Explorer and other tools.

When you scope the command locally, that is, without dot-sourcing, the Persist parameter does not persist the creation of a PSDrive beyond the scope in which you run the command. If you run New-PSDrive inside a script, and you want the new drive to persist indefinitely, you must dot-source the script. For best results, to force a new drive to persist, specify Global as the value of the Scope parameterin addition to adding Persist to your command.

The name of the drive must be a letter, such as D or E. The value of Root parameter must be a UNC path of a different computer. The value of the PSProvider parameter must be FileSystem.

To disconnect a Windows mapped network drive, use the Remove-PSDrive cmdlet. When you disconnect a Windows mapped network drive, the mapping is permanently deleted from the computer, not just deleted from the current session.

Mapped network drives are specific to a user account. Mapped network drives that you create in sessions that are started by using the Run as administrator option or by using the credential of another user are not visible in a session that was started without explicit credentials, or by using the credentials of the current user.

关于powershell - 在 powershell 中安装永久驱动器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47755300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com