Solved

Net use * /d /y

Posted on 2006-11-28
8
4,777 Views
Last Modified: 2008-02-26
Hi guys!

Often I have to map up to 10 drive letters to different machines.
When I log on, I get 2 drive mappings through logon script, they are S: and T:.

What Id like to find is a quick way to remove all my drive mappings through script, except keep S: and T:
I cant use:
net use * /d /y
because that will remove S: and T:

Do you guys know how I could quickly remove all drive mappings in a batch file except retain S: and T: ?
Thanks guys

Simon
0
Comment
Question by:Simon336697
  • 4
  • 3
8 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18030745
for /f "skip=3 tokens=2" %a in ('net use') do if not [%a]==S: if not [%a]==T: net use %a /del /y
0
 
LVL 1

Author Comment

by:Simon336697
ID: 18030863
Hi Sirbounty!

Thanks for your help on this mate.
I tried this script but it doesnt seem to remove the mapped drives Sirbounty.

Simon
0
 
LVL 1

Author Comment

by:Simon336697
ID: 18030899
Sirbounty!

Here is the output:

D:\>map.cmd
a] was unexpected at this time.

D:\>for /f "skip=3 tokens=2" a]==S: if not [ net use a /del /y
0
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 250 total points
ID: 18030912
type-o on my part...

for /f "skip=3 tokens=2" %a in ('net use') do if not [%a]==[S:] if not [%a]==[T:] net use %a /del /y
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 1

Author Comment

by:Simon336697
ID: 18030958
Sorry to be a pain:

D:\>simon.cmd
a] was unexpected at this time.

D:\>for /f "skip=3 tokens=2" a]==[S:] if not [] net use a /del /y

0
 
LVL 38

Accepted Solution

by:
Shift-3 earned 250 total points
ID: 18031102
Change each instance of %a to %%a if you're running it in a .cmd file.
0
 
LVL 1

Author Comment

by:Simon336697
ID: 18031188
Sir Bounty

Thanks mate that works.

Simon
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18032911
Had to cut the grass...glad you got it sorted. :^)
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Batuhan Cetin In this article I will be guiding through the process of removing a failed DC metadata from Active Directory (hereafter, AD) using the ntdsutil tool in a Windows Server 2003 environment. These steps are not necessary in a Win…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
A short film showing how OnPage and Connectwise integration works.

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now