我在删除脚本中用户的特定驱动器时遇到问题。 我无法使用 NET USE,因为它已被代替我的安全人员删除。 Remove-PSDrive -Name X 仅为 PS shell 而不是用户的资源管理器删除它。
有什么想法吗?
最佳答案
你要找的是 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)
关于powershell - Remove-PSDrive 不会删除映射的驱动器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57525706/