Loading
Scriptbox
 VBScript Links 
 About VBscript 
 JavaScript Links 
 About JavaScript 
 Powershell Links 
 PSCRIPT the Script Launcher 
 PowerShell Shortcut Keys 
 About Powershell 
     VBScript
    JavaScript
    Powershell
Disclaimer
Contact
Latest 10 Scripts
Script search
  :: { Category } :: 0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ
         

Search Options:  Use  a  Search    to  Move  Similar  Active  Directory  Objects  

 Content of Use a Search to Move Similar Active Directory Objects.vbs
MD5 Hash: 4AE3CBB40C5CDA7740AFABB4AA3F7D3D
' Description: Searches for all user account objects whose department attribute is Human Resources. The script then moves the user accounts that are not already in the HR OU to this OU.


Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

objCommand.CommandText = _
";" & _
"(&(&(objectCategory=person)(objectClass=user)" & _
"(department=Human Resources)));" & _
"ADsPath,distinguishedName, name;subtree"

Set objRecordSet = objCommand.Execute
Set objOU = GetObject("LDAP://ou=HR,dc=NA,dc=fabrikam,dc=com")

Do Until objRecordset.EOF
strADsPath = objRecordset.Fields("ADsPath")

strDNRecord=lcase(objRecordset.Fields("distinguishedName"))
strDNCompare=lcase("cn=" & objRecordset.Fields("name") & _
",ou=HR,dc=NA,dc=fabrikam,dc=com")

If strDNRecord <> strDNCompare Then
objOU.MoveHere strADsPath, vbNullString
WScript.Echo objRecordset.Fields("distinguishedName") & " Moved."
Else
Wscript.Echo objRecordset.Fields("distinguishedName") & " Not Moved."
End If
objRecordSet.MoveNext
Loop

objConnection.Close

   © 2008 - 2013 Boris Toll      :: Scripts available: 6.481 ::      :: scriptbox.toll.at ::      :: powered by www.toll.at ::
  Google Entries:n/a
  Yahoo Backlinks:n/a
  Live Backlinks:n/a
  del.icio.us Bookmarks:n/a
  Technorati Links:n/a