Hi,
I want to move computer/device from one OU to another OU using VB Code.
The below code is working great under login of service account into target PC.
but is there any way to execute below code with different credentials. I did google and tried but not able to make it work?
if you guys have worked on this scenario and please share some thoughts?
' ***************************************************************************** strLDAPofOU="OU=Desktops,OU=Computers,DC=domain,DC=locale" ' ***************************************************************************** On Error Resume Next 'Get MachineObjectOU Value Set wshNetwork = CreateObject("WScript.Network") Set oFso = CreateObject("Scripting.FileSystemObject") Set objSysInfo = CreateObject( "ADSystemInfo" ) Set ArgObj = WScript.Arguments 'Use first argument as target OU strMachineObjectOU = strLDAPofOU strComputerDN = objSysInfo.ComputerName 'msgbox(strMachineObjectOU) nComma = InStr(strComputerDN,",") strCurrentOU = Mid(strComputerDN,nComma+1) strComputerName = Left(strComputerDN,nComma - 1) 'msgbox(strCurrentOU) 'If current ou is different than target OU. Move object If UCase(strCurrentOU) <> UCase(strMachineObjectOU) Then Set objNewOU = GetObject("LDAP://" & strMachineObjectOU) Set objMoveComputer = objNewOU.MoveHere("LDAP://" & strComputerDN, strComputerName) 'msgbox("LDAP://" & strComputerDN & strComputerName) End If '//---------------------------------------------------------------------------- '// End Script '//----------------------------------------------------------------------------
Regards
Er Reddy