Sunday, December 25, 2005

UdriveSetup.cmd: Create network drive

Author: Robert Lawson
Environment: Windows Server, Active Directory
Description: This command is used to manually setup a network share for a user. This was used to test syntax and use of xcacls. Domain Admin membership required to run.
Code:
@ECHO OFF
rem file : UdriveSetup.cmd
rem purpose: setup network share drive
rem create : 25-dec-2005/r lawson
rem
rem notes
rem 1. Download xcacls from microsoft
rem 2. Follow setup from KB# 825751
rem 3. Change user name for 'edummy'
rem
rem UdriveSetup.cmd edummy \\server1\UserStore
rem UdriveSetup.cmd edummy c:\temp
SET THISCOMMAND=%0
SET LOGFILE=%TEMP%\UdriveSetup.log

:checkForHelp
@if /i [%1] == [-h] (goto usage)
@if /i [%1] == [/h] (goto usage)
@if /i [%1] == [-?] (goto usage)
@if /i [%1] == [/?] (goto usage)
@if /i [%1] == [-help] (goto usage)
@if /i [%1] == [/help] (goto usage)

:verifyParams
@if [%1] == [] (goto parameterError)
@if [%2] == [] (goto parameterError)
SET NEWDIRECTORY=%2\%1
goto verifyDirectory

:parameterError
@Echo %DATE% %TIME% FAILED: Not enough parameters>>%LOGFILE%
goto end

:verifyDirectory
rem @if /i NOT EXIST [%NEWDIRECTORY%] (goto Execute)
DIR %NEWDIRECTORY%>NUL
IF ERRORLEVEL 1 GOTO Execute
@Echo %DATE% %TIME% FAILED: Directory already exists>>%LOGFILE%
goto end

:usage
@echo Create a network U drive for a user
@echo
@echo Usage: %THISCOMMAND% [sAMAccountname] [UNC]
@echo
@echo [sAMAccountname] = user id
@echo [UNC] = Where to create directory using the sAMAccountname
@echo
pause
goto end

:Execute
MKDIR %NEWDIRECTORY%
rem remove the /Q to display
"%SystemRoot%\system32\cscript.exe" "%SystemRoot%\system32\xcacls.vbs" %NEWDIRECTORY% /O SOKA/%1 /I ENABLE /Q
@Echo %DATE% %TIME% SUCCESS: Directory created: %NEWDIRECTORY%>>%LOGFILE%

:end
ENDLOCAL

No comments: