Re: Moving computer account to another OU



Vole wrote:

I would like to move computer accounts from "computers" OU to another OU
with automated scrtipt. Operating system has to be the ruler.

Example, if OS is Windows XP then computer account moves to "OU1" and if
OS
is Window server 2003 account moves to "OU2"

I have this kind of script that moves "by name", but I cant get it work
"by
operating system version"

This is the "by name" script:


Dim colComputers, objComputer, objDestOU
'Edit the LDAP path as needed
Set colComputers =
GetObject("LDAP://xxx.xxx.com/cn=computers,dc=xxx,dc=com";)
For Each objComputer In colComputers
strSystemName = Trim(Mid(objComputer.Name, 4))
Set objDestOU = Nothing
If InStr(1, LCase(strSystemName), "computer1") Then
'Edit the LDAP path as needed
Set objDestOU = GetObject("LDAP://ou=xxx,dc=xxx,dc=com";)
Else
If InStr(1, LCase(strSystemName), "computer2") Then
'Edit the LDAP path as needed
Set objDestOU = GetObject("LDAP://ou=xxx,dc=xxx,dc=com";)
End If
End If
If Not IsNothing(objDestOU) Then
objDestOU.Movehere objComputer.ADsPath, vbNullString
End If
Next
Set objComputer = Nothing
Set colComputers = Nothing

Function IsNothing(Obj)
If TypeName(Obj) = "Nothing" Then
IsNothing = True
Else
IsNothing = False
End If
End Function


You can use the operatingSystem attribute of the computer object in most
cases. For example:
============
' Bind to the Computers container in the domain. No need to specify a DC.
Set objContainer = GetObject("LDAP://cn=Computers,dc=MyDomain,dc=com";)

' Filter on objects of class "computer".
objContainer.Filter = Array("computer")

' Bind to OU1 for XP computers (no need to bind more than once).
Set objOU1 = GetObject("LDAP://ou=OU1,dc=MyDomain,dc=com";)

' Bind to OU2 for Windows Server 2003 computers.
Set objOU2 = GetObject("LDAP://ou=OU2,dc=MyDomain,dc=com";)

' Enumerate the computer objects.
For Each objComputer In objContainer
' Retrieve operating system.
strOS = objComputer.operatingSystem
' Check operating system.
If (InStr(LCase(strOS), "windows xp") > 0) Then
objOU1.MoveHere objComputer.AdsPath, vbNullString
ElseIf (InStr(LCase(strOS, "windows server 2003") > 0) Then
objOU2.MoveHere objComputer.AdsPath, vbNullString
End If
Next
=======
You could also retrieve version number and other information, but that would
require connecting with WMI.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--


.



Relevant Pages

  • Re: I want to migrate to Linux
    ... Microsoft considers the x86 platform to still be what it was when it was ... Dirty Operating System"; not to be confused with the Q-DOS ... 1.x versions had a GUI called Presentation Manager, from which the Windows ... Thompson has stated that GNU/Linux and cousins are all de facto UNIX ...
    (comp.os.linux.hardware)
  • Re: Newbie to WCE!
    ... Windows CE, which is a full-blown operating system, just like Windows XP, ... the chip maker for the BSP if they have one (there ... All I want to know is can I buy a microcontroller chip (One of the chips ...
    (microsoft.public.windowsce.embedded)
  • [Full-disclosure] - IRISH VIRUS - DoS Security Bypass and System access
    ... THE operating system ... Apple Computer Apple DOS ... Windows CE ... LOLDONGS Research, a Wholly Owned Subsidiary of Banned Town Security ...
    (Full-Disclosure)
  • Re: Why most run Microsoft, not RedHat
    ... re-install has happened more than that. ... Heck, even Steve Ballmer, CEO for Microsoft needs to re-install Windows ... We have an enterprise grade firewall behind the router. ... The main problems I encounter again and again are with clueless operators who've ignored repeated instructions about dangerous surfing practices and clicking on attachments - those are the two most common causes of problems - are they caused by the operating system? ...
    (Fedora)
  • Novell Client login form enables reading and writing from and to the clipboard of the logged-in
    ... Novell Client for Windows, ... Anyone with access to the computer's local operating system console, ... inject its own textual content into the clipboard of the currently logged-in ...
    (Bugtraq)