How to clean up old connections before mapping a new drive?

I have scripts on Windows Server 2008r2 that access specific resources on other server systems using limited credentials. If a person or other script has also accessed that system from this server with different credentials and didn't log out, scripts fail with Error 1219 "The network folder specified is currently mapped using a different user name and password"

How to ensure that my script deletes all connections to this specific machine before trying to map a new drive?

C:\> net use //server /d  

doesn't work on its own. I can follow it up with net use and see that a drive is still shared:

C:\> net use \\server /d
\\server was deleted successfully.


C:\> net use
New connections will be remembered.


Status       Local     Remote                    Network

-------------------------------------------------------------------------------
Disconnected           \\server\somedrive       Microsoft Windows Network
The command completed successfully.

The disconnected drive will still cause the same Error 1219.

Can anyone suggest a more elegant solution than deleting an exhaustive list of all shares that exists on that machine?

net use \\server\share1 /d
net use \\server\share2 /d
net use \\server\share3 /d
etc...

Also

net use \\server\* /d

fails with "connection not found".


The command is:

net use /d * /y