Reputation: 75
I am having trouble deleting a specific drive for a user in my script. I cannot use NET USE as it is removed by security guys in my place. Remove-PSDrive -Name X only removes it for the PS shell not the user's explorer.
any thoughts?
Upvotes: 3
Views: 2510
Reputation: 4020
What you are after is the WScript.Network Com Object.
# Create new object
$NetDrive = new-object -ComObject WScript.Network
# Remove the network drive (Drive Letter, Force Removal, Remove Mapping)
$NetDrive.RemoveNetworkDrive('X:',$True,$True)
Without doing $True
twice, it will only disconnect the mapped drive.
You can map it by doing the below.
# Add the network drive (Drive Letter, Path, Persistent, Username, Password)
$NetDrive.MapNetworkDrive($drive, $path, "true", $user, $pwd)
Upvotes: 5