#33661 - 2002-12-02 05:05 PM
Re: Check if a share is mapped to
|
Julian
Starting to like KiXtart
Registered: 2000-04-20
Posts: 112
Loc: Newcastle, Staffs, UK
|
Hi, I thought i'd post my updated script to move the directories with the addition of Howard Bullock's Win32Admin.dll function. I havnt run it in a live system yet but have done some testing and it all seems to be working.
code:
Break On Cls
;Directory and Source Variables $SourceDir="D:\Sys\Users\" ; Local source path of user directories $MappedDrive="E:\" ; Drive mapped to user share at other location $SourceServer="\\CONGRESS-SVR1\" ; Server where original user dir is held $DestServer="\\SVRCONGRESS\" ; Server where new user dir is to be copied $DestSharePath="D:\Users\" ; directory on destination server to the path of the user directory $PDC="SVRSTOKE" ; Primary Domain Controller $HomeDirDrive="U:\" ; Home drive $UserDirServer="CONGRESS-SVR1" ; Server holding the user directories $Win32Admin = CreateObject("Win32Admin")
;Start Move $UserDirList="G:\MoveDirs\Dirs.txt" Open(1,$UserDirList,2) $Dir=Readline(1) While $Dir<>"" $SourceShare=$SourceServer + $Dir ; Share on source server to be removed $DestShare=$DestServer + $Dir ; Share on destination server to be created $SourceUserDir=$SourceDir + $Dir ; Path of the user dir on source server $DestUserDir=$DestSharePath + $Dir ; Path of the user dir on destination server $RmtUserDir=$MappedDrive + $Dir ; Location on the source server of the destination path $Info = $Win32Admin.NetShareGetInfo ($UserDirServer, $Dir) If $Info[+9] = 0 Shell "RmtShare $SourceShare /DELETE" Shell "Robocopy $SourceUserDir $RmtUserDir /E /SEC /MOVE /XF paradox.cfg /LOG+:MoveUserDir.txt" Shell "Robocopy $SourceUserDir $RmtUserDir paradox.cfg /SEC /LOG+:MoveUserDir.txt" Shell "RmtShare $DestShare=$DestUserDir" Shell "NTUser -s $PDC change $Dir -home_dir $DestServer$Dir -home_dir_drive $HomeDirDrive" EndIf $Dir=Readline(1) Loop Close(1) Return
Thanks especially to Howard Bullock who added another funtion to his Win32Admin.dll which allowed me to do this.
Can I just ask though, have I used the function correctly or is there a better way of doing it?
Thanks
Ju
|
|
Top
|
|
|
|
#33662 - 2002-12-02 07:36 PM
Re: Check if a share is mapped to
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I think you need more error checking and you do not need to use Rmtshare.exe anymore.
I have added some lines to give you an idea. I also fixed the $Info[+9] to $Info[9]. code:
Break On Cls
;Directory and Source Variables $SourceDir="D:\Sys\Users\" ; Local source path of user directories $MappedDrive="E:\" ; Drive mapped to user share at other location $SourceServer="\\CONGRESS-SVR1\" ; Server where original user dir is held $DestServer="\\SVRCONGRESS\" ; Server where new user dir is to be copied $DestSharePath="D:\Users\" ; directory on destination server to the path of the user directory $PDC="SVRSTOKE" ; Primary Domain Controller $HomeDirDrive="U:\" ; Home drive $UserDirServer="CONGRESS-SVR1" ; Server holding the user directories
$Win32Admin = CreateObject("Win32Admin") ; Add proper error checking. ; You will find a script failure eventually and have no idea why. if vartypename($Win32Admin) <> "Object" ? "@serror" exit 1 endif
;Start Move $UserDirList="G:\MoveDirs\Dirs.txt" Open(1,$UserDirList,2) $Dir=Readline(1) While $Dir<>"" $SourceShare=$SourceServer + $Dir ; Share on source server to be removed $DestShare=$DestServer + $Dir ; Share on destination server to be created $SourceUserDir=$SourceDir + $Dir ; Path of the user dir on source server $DestUserDir=$DestSharePath + $Dir ; Path of the user dir on destination server $RmtUserDir=$MappedDrive + $Dir ; Location on the source server of the destination path $Info = $Win32Admin.NetShareGetInfo ($UserDirServer, $Dir) If $Info[9] = 0 ;Shell "RmtShare $SourceShare /DELETE" if $Win32Admin.NetShareDel ("CONGRESS-SVR1", $Dir) ? "Share deletion successful." else ? "Error @serror" endif Shell "Robocopy $SourceUserDir $RmtUserDir /E /SEC /MOVE /XF paradox.cfg /LOG+:MoveUserDir.txt" Shell "Robocopy $SourceUserDir $RmtUserDir paradox.cfg /SEC /LOG+:MoveUserDir.txt" ;Shell "RmtShare $DestShare=$DestUserDir" if $Win32Admin.NetShareAdd ("SVRCONGRESS", "myShare", "STYPE_DISKTREE", "User Home Share", -1, "D:\Users\$UserID") ? "Share successfully created" else ? "Error @serror" endif
Shell "NTUser -s $PDC change $Dir -home_dir $DestServer$Dir -home_dir_drive $HomeDirDrive" EndIf $Dir=Readline(1) Loop Close(1) Return
|
|
Top
|
|
|
|
#33663 - 2002-12-03 09:56 AM
Re: Check if a share is mapped to
|
Julian
Starting to like KiXtart
Registered: 2000-04-20
Posts: 112
Loc: Newcastle, Staffs, UK
|
I think i now have a spot on script. Thanks for your help.
|
|
Top
|
|
|
|
#33664 - 2002-12-03 02:50 PM
Re: Check if a share is mapped to
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Also, if the share is in use you should log that info I think. If you are successful in copying the directory, then you should SetUserProps to update the user's account properties so that he can connect at next logon. [ 03. December 2002, 14:52: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#33665 - 2002-12-03 02:56 PM
Re: Check if a share is mapped to
|
Julian
Starting to like KiXtart
Registered: 2000-04-20
Posts: 112
Loc: Newcastle, Staffs, UK
|
The NTUser part updates the user account properties. Although I suppose I could make the relevant changes to use SetUserProps instead.
Thanks
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 1198 anonymous users online.
|
|
|