Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Sylvain Le Courtois

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

ASP Page listing and making changes to AD accounts

// Used for automated AD account migration
   1  
   2  <HTML><HEAD><TITLE>Workstation User Account migration</TITLE>
   3  <META http-equiv=Content-Type content="text/html; charset=iso-8859-1"><LINK 
   4  href="files/v2006.css" type=text/css rel=stylesheet>
   5  <BODY leftMargin=0 topMargin=30 marginwidth="0" marginheight="0">
   6  <CENTER>
   7  <%
   8  ' ------------------------------------------------------------------------
   9  Const ADS_PROPERTY_CLEAR = 1
  10  
  11  Const SOURCE_OU="ou=NT Users,ou=NT,dc=fr,dc=erm,dc=int"
  12  Const TARGET_OU="ou=SUPPORT SERVICES,dc=fr,dc=erm,dc=int"
  13  
  14  Const HOMES_PATH="\\frsrvfil0001\USERS\"
  15  Const PROFILES_PATH="\\frsrvfil0001\PROFILES\"
  16  
  17  Const ADMIN_HOMES_PATH_SOURCE="\\frsrvfil0001\U$\NT\"
  18  Const ADMIN_PROFILES_PATH_SOURCE="\\frsrvfil0001\P$\NT\"
  19  Const ADMIN_HOMES_PATH_DEST="\\frsrvfil0001\U$\"
  20  Const ADMIN_PROFILES_PATH_DEST="\\frsrvfil0001\P$\"
  21  
  22  Const SCRIPT_NAME="ntuser_to_xp.asp"
  23  
  24  Dim State
  25  State="Init"
  26  Dim OU, Member
  27   
  28  If Request.QueryString("login") <> "" Then
  29  		' Affichage formulaire pour modif du compte
  30  		State="Info"
  31  End If
  32  If Request.Form("login") <> "" Then
  33  		' On a cliqué sur OK pour valider le formulaire
  34  		State="Modify"
  35  End If
  36  ' ------------------------------------------------------------------------
  37  %>
  38  <TABLE cellSpacing=0 cellPadding=1 width=500 align=center bgColor=#26333e 
  39  border=0>
  40    <TBODY>
  41    <TR>
  42      <TD>
  43        <TABLE cellSpacing=0 cellPadding=1 width=500 align=center border=0>
  44          <TBODY>
  45          <TR bgColor=#f0f3f5>
  46            <TD width=160 valign="top"><IMG height=116 src="files/man_portable.jpg" 
  47              width=160> </TD>
  48            <TD width=302 bgColor=#e5ebef>
  49  
  50  <%
  51  	If State="Init" Then
  52  	'-----------------------------------------------------------------------------------
  53  	' Listing of the NT Users
  54  	'-----------------------------------------------------------------------------------
  55  %>          
  56  
  57              <TABLE cellSpacing=4 cellPadding=4 width="100%" align=center 
  58              border=0>
  59                <TBODY>
  60                <TR>
  61                  <TD class=medium colSpan=3 height=22>
  62                      <%
  63                      'Response.Write(SOURCE_OU & "<BR>") 
  64                      %>
  65  					Please select the NT 4.0 Workstation user account to migrate
  66                  </TD></TR>
  67                  
  68                <TR>
  69                  <TD class=td11 height=22>
  70                                    <%
  71                    Set OU = GetObject("LDAP://" & SOURCE_OU)
  72                    OU.Filter = Array("user")
  73      	          For Each Member In OU
  74      	          		' Bug with the SMS Account ??
  75      	          		If Member.Name <> "CN=SMSService" Then 
  76      	          		If Member.AccountDisabled = 0 Then
  77  	    	                Response.Write("<A HREF=""" & SCRIPT_NAME & "?login=" & Server.URLEncode(Member.Name) & """>" & Member.FullName & "</A><BR>")
  78  	    	            End If
  79  	    	            End If 
  80              	  Next      
  81                    
  82                    %>
  83  
  84                  </TD>
  85                  </TR>
  86                  
  87                  </TBODY></TABLE>
  88  
  89  <%
  90  End If
  91  %>                
  92                  
  93  <%
  94  	If State="Info" Then
  95  	'-----------------------------------------------------------------------------------
  96  	' Information page about the NT Users
  97  	'-----------------------------------------------------------------------------------
  98  %>          
  99  			<FORM method=post>
 100  
 101              <TABLE cellSpacing=4 cellPadding=4 width="100%" align=center 
 102              border=0>
 103                <TBODY>
 104                <TR>
 105                  <TD class=medium colSpan=2 height=22>
 106                   	<%
 107                   	Response.Write("Windows NT 4.0 User Account Migration")
 108                      %>
 109  					
 110                  </TD></TR>
 111                 
 112                    <%
 113                    Sub TabRow(v1,v2)
 114                    		Response.Write("<TR class=td11 height=16><TD><B>" & v1 & "</B>")
 115                    		Response.Write("<TD>" & v2 & "</TD>")
 116                    		Response.Write("</TD></TR>")
 117                    End Sub
 118                    Set Member = GetObject("LDAP://" & Request.QueryString("login") & "," & SOURCE_OU)
 119  
 120                    TabRow "User Name",Member.FullName
 121                    TabRow "NT Login",Member.sAMAccountName
 122  				  TabRow "Login Script", Member.LoginScript & " (to delete)"
 123  				  TabRow "Profile Path", Member.Profile
 124  				  TabRow "New Path",PROFILES_PATH & Member.sAMAccountName
 125  				  TabRow "Home Folder", Member.HomeDirectory
 126  				  TabRow "New Path",HOMES_PATH & Member.sAMAccountName
 127  				  
 128  				  ' Liste des OU dans SUPPORT SERVICES
 129   				  Dim OUSuppServices, Entity, BoxList
 130   				  Set OUSuppServices=GetObject("LDAP://" & TARGET_OU)
 131  				  OUSuppServices.Filter = Array("organizationalUnit")
 132  				  BoxList="<SELECT NAME=""entity"">"
 133  				  For Each Entity in OUSuppServices
 134  				  	BoxList= BoxList & "<OPTION VALUE=""" & Entity.Name & """>" & Mid(Entity.Name,4) & "</OPTION>"
 135  				  Next
 136  				  BoxList=BoxList & "</SELECT>"
 137  				  TabRow "Organizational Unit",BoxList
 138                                      
 139                    %>
 140  
 141                  
 142                  </TBODY></TABLE>
 143                  <BR>
 144                  <INPUT name=login type=hidden value=<% Response.Write(Member.sAMAccountName) %> >
 145                  <INPUT type=image height=18 alt="GO !" width=15 src="files/submit.gif" value=login border=0 name=ok>
 146                  &nbspCliquer ici pour migrer ce compte.<BR><BR>
 147                  ATTENTION, l'utilisateur ne doit pas être connecté ! 
 148                  <% Response.Write("<BR><BR><A HREF=""" & SCRIPT_NAME & """>" & "Cliquer ICI pour annuler" & "</A><BR>") %>
 149                  </FORM>
 150  
 151  <%
 152  End If
 153  %>                
 154  
 155  <%
 156  
 157  	If State="Modify" Then
 158  	'-----------------------------------------------------------------------------------
 159  	' Migration of the NT Users
 160  	'-----------------------------------------------------------------------------------
 161  Sub dirMoveTree(source, dest)
 162  	Response.Write "Deplacement de <B>" & source & " vers " & dest & "</B><BR>"
 163  	Dim Folder,File,SubFolder
 164  	set Folder=fso.GetFolder(source)
 165  	For Each File In Folder.Files
 166  	      Response.Write File.Name & " File -> " & dest & "<BR>"
 167  	      file.move dest & "\"
 168  	Next
 169  	For Each SubFolder In Folder.SubFolders
 170  	      Response.Write SubFolder.Name & " Folder -> " & dest & "<BR>"
 171  	      SubFolder.move dest & "\"
 172  	Next
 173  End Sub
 174  
 175  %>          
 176  <CENTER>
 177  Windows NT 4.0 User Account Migration<BR><BR>
 178  <%
 179  
 180  ' Modification des proprietes l'utilisateur dans AD
 181  Set Member = GetObject("LDAP://" & Request.QueryString("login") & "," & SOURCE_OU)
 182  
 183  ' ADS_PROPERTY_CLEAR
 184  Member.PutEx 1, "scriptPath", 0
 185  Member.SetInfo
 186  
 187  Member.Put "profilePath", PROFILES_PATH & Member.sAMAccountName
 188  Member.Put "homeDirectory", HOMES_PATH & Member.sAMAccountName
 189  ' 
 190  Member.SetInfo
 191  ' 
 192  Response.Write("Utilisateur <B>" & Member.sAMAccountName & "</B> Modifié dans AD<BR><BR>")
 193  
 194  ' Deplacement dans le bon conteneur
 195  Set OU = GetObject("LDAP://" & "OU=Users," & Request.Form("entity") & "," & TARGET_OU)
 196  OU.MoveHere "LDAP://" & Request.QueryString("login") & "," & SOURCE_OU, Request.QueryString("login")
 197  Response.Write("Utilisateur <B>" & "LDAP://" & Request.QueryString("login") & "," & SOURCE_OU & "</B> Deplacé dans " & "LDAP://" & "OU=Users," & Request.Form("entity") & "," & TARGET_OU & "<BR><BR>")
 198  
 199  DIM fso, File, Folder, SubFolder
 200  Set fso = CreateObject("Scripting.FileSystemObject")
 201  
 202  ' Creation des repertoires cible
 203  
 204  fso.CreateFolder(ADMIN_HOMES_PATH_DEST & Request.Form("login"))
 205  fso.CreateFolder(ADMIN_PROFILES_PATH_DEST & Request.Form("login"))
 206  
 207  ' Deplacement des données
 208  
 209  dirMoveTree ADMIN_HOMES_PATH_SOURCE & Request.Form("login"),ADMIN_HOMES_PATH_DEST & Request.Form("login")
 210  dirMoveTree ADMIN_PROFILES_PATH_SOURCE & Request.Form("login"),ADMIN_PROFILES_PATH_DEST & Request.Form("login")
 211  
 212  ' Applications des ACLs, en arriere plan car ca peut etre long !
 213  Response.Write("<BR>Creation du script d'application des ACLs C:\Inetpub\wwwroot\techcity\xcacls_" & Request.Form("login") & ".cmd<BR><BR>")
 214  Set server_shell = Server.CreateObject("wscript.shell")
 215  
 216  server_shell.Run "cmd /c echo echo Excecution Cacls >C:\Inetpub\wwwroot\techcity\xcacls_" & Request.Form("login") & ".cmd 2>&1",,1
 217  server_shell.Run "cmd /c echo xcacls.exe """ & ADMIN_HOMES_PATH_DEST & Request.Form("login") & """ /T /C /G SYSTEM:F ADMINISTRATORS:F FR-ERM\" & Request.Form("login") & ":C /Y >>C:\Inetpub\wwwroot\techcity\xcacls_" & Request.Form("login") & ".cmd 2>&1",,1
 218  server_shell.Run "cmd /c echo xcacls.exe """ & ADMIN_PROFILES_PATH_DEST & Request.Form("login") & """ /T /C /G SYSTEM:F ADMINISTRATORS:F FR-ERM\" & Request.Form("login") & ":F /Y >>C:\Inetpub\wwwroot\techcity\xcacls_" & Request.Form("login") & ".cmd 2>&1",,1
 219  
 220  ' server_shell.Run "C:\Inetpub\wwwroot\techcity\xcacls.cmd >C:\Inetpub\wwwroot\techcity\xcacls.log 2>&1",,1
 221  Response.Write("<BR>Les ACLs seront appliquee dans 5 min (scheduled)...<BR><BR>")
 222  Response.Write("Attendre egalement la fin de replication de AD ...<BR><BR>")
 223  
 224  Response.Write("<BR>Terminé !<BR>")
 225  
 226  %>
 227  <% Response.Write("<BR><BR><A HREF=""" & SCRIPT_NAME & """>" & "Cliquer ICI pour quitter" & "</A><BR>") %>
 228  </CENTER>
 229  <%
 230  End If
 231  %>                
 232  
 233  
 234                </TD></TR>            
 235                  
 236                  </TBODY></TABLE></TD></TR>
 237                          
 238                  
 239  </TBODY></TABLE></CENTER></BODY></HTML>
 240  
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS