2012年5月9日 星期三

如何大量更改Home Folder路徑


公司要換主機,事前準備項目很繁瑣,例如像Home folder就要改,而且必須每個帳號都更改。如果有3500個帳號或更多,可能會改到要離職。


還好,有了這支偉大程式,讓辛苦的MIS人員,不用熬夜加班,快樂回家做家事。

程式碼改前面兩行即可,存成vbs檔在DC上執行即可。
==============================================
strNewServer = "ServerName"
strContainerDN = "OU=Users,DC=abc,DC=com"

' Bind to container.
Set objContainer = GetObject("LDAP://" & strContainerDN)
' Filter on user objects.
objContainer.Filter = Array("user")
' Enumerate users in container.
For Each objUser In objContainer
  ' Read existing homeDirectory.
  strHomeDirectory = objUser.homeDirectory
  If strHomeDirectory <> "" Then
    ' Strip off server name from UNC path.
    intIndex = InStr(3, strHomeDirectory, "\")
      If intIndex > 3 Then
      ' Home folder with server name stripped off.
      strPath = Mid(strHomeDirectory, intIndex)
      ' Construct new homeDirectory.
      strNewHome = "\\" & strNewServer & strPath
      objUser.Put "homeDirectory", strNewHome
      objUser.SetInfo
    End If
  End If
Next