Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5245
  • Last Modified:

Net use * /d /y

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
Simon336697
Asked:
Simon336697
  • 4
  • 3
2 Solutions
 
sirbountyCommented:
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
 
Simon336697Author Commented:
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
 
Simon336697Author Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
sirbountyCommented:
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
 
Simon336697Author Commented:
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
 
Shift-3Commented:
Change each instance of %a to %%a if you're running it in a .cmd file.
0
 
Simon336697Author Commented:
Sir Bounty

Thanks mate that works.

Simon
0
 
sirbountyCommented:
Had to cut the grass...glad you got it sorted. :^)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now