Mapping of network drives via batchfile

If you work in a ActiveDirectory based environment and all your clients are connected to the domain, you might not have to deal with manually map home drives and other resources.

However, if some of your clients are not connected to the domain, but need access to domain resources, you probably noticed that it can be pretty annoying having service calls because of forgotten network paths and locked accounts.

To encounter that problem, I wrote a quick and dirty script, which gives the user a basic dialogue driven netdrive-mapper, so your service desk gets rid of the most basic calls.


@ECHO OFF

ECHO Removing all available mappings...
PAUSE
NET USE * /D

:USER
ECHO Attempting to connect to SERVER and map your homedrive...
PAUSE
SET /P USER=Please enter your username (username@domain.local):
NET USE U: \\server.domain.local\%USER:~0,-13%$ /USER:%USER% /PERSISTENT:NO

ECHO Attempting to connect to SERVER and map your Groupdrives...
PAUSE

:GROUP1
SET /P GROUP1=Please enter your main Group:
NET USE V: \\server.domain.local\%GROUP1% /PERSISTENT:NO
SET /P CONTINUE=Add another Groupdrive? (y or n)

IF /I '%CONTINUE%'=='y' GOTO GROUP2
IF /I '%CONTINUE%'=='n' GOTO PUB
ECHO "%CONTINUE%" is not valid. Going to map public drives GOTO PUB

:GROUP2
SET /P GROUP2=Please enter your second Group:
NET USE W: \\server.domain.local\%GROUP2% /PERSISTENT:NO
GOTO PUB

:PUB
ECHO Attempting to connect to SERVER and map public drives...
NET USE p: \\server.domain.local\public /USER:%USER% /PERSISTENT:NO
GOTO PRINTERS

:PRINTERS
ECHO Attempting to connect to SERVER and map printers...
PAUSE
START \\server.domain.local\printer1
START \\server.domain.local\printer2

Recursively delete files by extension

Recently, I got the task to remove all MP3- files from some shared folders (SMB shares). To do so, I wrote a tiny batch- script wich processes the DIR command’s output and examines it to match the MP3 extension.

Usage:
The script processes all folders and subfolders in its working directory (e.g. if you run it in c:\scripts it processes all folders and subfolders from there on – c:\scripts\*)


@ECHO OFF
FOR /F "tokens=*" %%G IN ('DIR /B /S *.mp3') DO DEL /F "%%G"