Re: Moving computer account to another OU
- From: "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 18 Apr 2008 10:47:04 -0500
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
--
.
- References:
- Moving computer account to another OU
- From: Vole
- Moving computer account to another OU
- Prev by Date: Re: Script Time Out Issue
- Next by Date: Re: Script Time Out Issue
- Previous by thread: Moving computer account to another OU
- Index(es):
Relevant Pages
|