Move computer object
From: HashMan (hashim.ismail_at_fac.com)
Date: 09/21/04
- Next message: HashMan: "RE: Actual login script needed"
- Previous message: Craig: "Re: WMI - NT Event Log"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 21 Sep 2004 08:21:06 -0700
Hi All;
I was wondering if you can point me to the right direction. I am trying to
write a script that will query the a list of computer and find who the users
are that are logged into them then move the computer object to user's OU. If
the user is logged into a computer resides in Accounting OU then I want the
computer object to move to that OU. Currently all the computer objects are
in Computer container. Thankx.
My Code thus far:
'\\\\Query Computer to list users that are logged on to them\\\\\
'\\\\Then query AD to locate user in the OU\\\\
'\\\\Move the computer object into user's OU\\\\
'\\\\Find the user logged on to the computer\\\\
dim strComputer, objConn, objWMIService, strName, objComputer, strUsername,
strQuery
dim strADspath, objUser
strComputer = inputbox("Enter the Path\Name of PC or Cancel to exit.", _
"PC Name")
Set objConn = CreateObject("ADODB.Connection")
objConn.Provider = "ADsDSOOBJECT"
objConn.Open
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer in colComputer
strName=objComputer.UserName
Wscript.Echo strName
'\\\\Find the OU the user belongs to\\\\
'Set strUsername=strName
strUsername=inputbox("Enter Username.", strName)
strQuery= "SELECT ADsPath FROM 'LDAP://DC=domain,DC=com' WHERE
objectclass='User' and SAMAccountName = '" & strUserName & "'"
Set objRecordSet = objConn.Execute(strQuery)
strADspath=objRecordSet.Fields("ADsPath")
Set objUser = GetObject(strADspath)
objUser.GetInfo
wscript.echo "User Information for......." & objUser.Get("SAMAccountName")
wscript.echo "AD Path............." & strADspath
Set objNewOU = GetObject(strADspath2)
Set objMoveComputer = objNewOU.MoveHere _
("LDAP://CN=" & strComputer & ",CN=Computers,DC=fac,DC=com")
Next
- Next message: HashMan: "RE: Actual login script needed"
- Previous message: Craig: "Re: WMI - NT Event Log"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|