Wednesday, 4 January 2012

DFS Share Command Line

On my home server I've configured a DFS share to present one shared folder to include files from 2 shared folders on separate hard disks. The script needs to be run every time a new folder is added to either of the shared folders.

This script is below:

@echo off
REM Clean up section
dfsutil root remove "\\MEDIA\TV Shows"
net share "TV Shows" /DELETE
rd "E:\ServerFolders\TV Shows"
REM Query the folders and output to two temp text files
dir \\MEDIA\TV1 /ad /b> TempTV1.txt
dir \\MEDIA\TV2 /ad /b> TempTV2.txt

md "E:\ServerFolders\TV Shows"
net share "TV Shows"="E:\ServerFolders\TV Shows"
dfsutil root addstd "\\MEDIA\TV Shows"
for /F "delims=*(()(" %%1 IN (TempTV1.txt) DO dfsutil link add "\\MEDIA\TV Shows\%%1" "\\MEDIA\TV1\%%1" "%%1"
for /F "delims=*(()(" %%1 IN (TempTV2.txt) DO dfsutil link add "\\MEDIA\TV Shows\%%1" "\\MEDIA\TV2\%%1" "%%1"
del TempTV1.txt
del TempTV2.txt

No comments:

Post a Comment