I was running into a frustrating issue where I had mapped a drive using a script and I could not disconnect anymore ?
Problem was that I could not open the mapped drive because in the background it was not available anymore ?
But when I tried to run a script to disconnect the drive. I saw a different message
So I now knew that the Z: drive was being locked by an other process.
Error : The device is in use by an active process and cannot be disconnected.
Firing up the Process Explorer revealed after searching on the keyword “Z:” the process ID 7936 was locking the drive ?
Pulling up a bit more details said that the WebClient service was involved.
Restarting the service gave me back the drive letter
I could then map the Z: drive again via a script and disconnect again, without having to restart the server each time.