【发布时间】:2019-12-22 20:11:48
【问题描述】:
我在为我的脚本中的用户删除特定驱动器时遇到问题。 我不能使用 NET USE,因为它已被我的安全人员删除。 Remove-PSDrive -Name X 只为 PS shell 而不是用户的资源管理器删除它。
有什么想法吗?
【问题讨论】:
标签: powershell powershell-3.0 powershell-5.0
我在为我的脚本中的用户删除特定驱动器时遇到问题。 我不能使用 NET USE,因为它已被我的安全人员删除。 Remove-PSDrive -Name X 只为 PS shell 而不是用户的资源管理器删除它。
有什么想法吗?
【问题讨论】:
标签: powershell powershell-3.0 powershell-5.0
你所追求的是WScript.Network Com 对象。
# Create new object
$NetDrive = new-object -ComObject WScript.Network
# Remove the network drive (Drive Letter, Force Removal, Remove Mapping)
$NetDrive.RemoveNetworkDrive('X:',$True,$True)
不执行两次$True,只会断开映射的驱动器。
您可以通过执行以下操作来映射它。
# Add the network drive (Drive Letter, Path, Persistent, Username, Password)
$NetDrive.MapNetworkDrive($drive, $path, "true", $user, $pwd)
【讨论】: