Os wise sorting of all machines in different Ou's

Posted on 2007-07-20
Last Modified: 2010-03-05

I need a script which can do Os wise sorting of all machines in different Ou's.

I have all machines scatterered in different OU's in many ways. So i need a way to move all machines  with win xp in one ou and win 2003 in another u and the rest in the 3rd ou.

Is there a way to specify movement in such manner.

Question by:bsharath
    LVL 31

    Expert Comment

    LVL 11

    Author Comment

    That is a different Q.In this Q i need to sort by OS.
    LVL 31

    Accepted Solution

    oh sorry :)
    This should work like this.....but the PC's have to be online when executing the script

    On Error Resume Next
    dim objFSO, objFile
    dim strComputer
    dim colItems ,objItem,objWMIService

    set objFSO = CreateObject("Scripting.FileSystemObject")
    set objFile = objFSO.OpenTextFile("C:\YourPCs.txt)
    Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand =   CreateObject("ADODB.Command")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open "Active Directory Provider"
    Set objCommand.ActiveConnection = objConnection
    objCommand.Properties("Page Size") = 1000
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
    objOU = GetObject("LDAP://ou=YourOU,dc=YourDomain,dc=com") ' Change the specified OU and Domain here

    do while not objFile.AtEndOfStream
          strComputer = objFile.ReadLine

          Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
          Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem)

    for each objItem in colItems
       If objItem.Caption = "Microsoft Windows XP Professional" then

          objCommand.CommandText = "SELECT ADsPath FROM 'LDAP://dc=YourDomain,dc=com' WHERE objectCategory='computer' AND Name='" &strComputer  &"'"
                Set objRecordSet = objCommand.Execute


                Do Until objRecordSet.EOF
                   strADsPath = objRecordSet.Fields("ADsPath").Value
                   objOU.MoveHere strADsPath, vbNullString
          'Do Nothing
       End If
    LVL 1

    Expert Comment

    try csvde first to export your active directory list to an excel readable format.

    from there you might  manually do the transfers using any reference you may get from the csv file
    (it has other fields too not listed in active directory, got to try it)
    LVL 11

    Author Comment

    What does this script above do?

    I tried this and no changes took place.I changed the OU name in the script too.
    LVL 11

    Author Comment

    Any way to move even when the machines are offline.?
    LVL 31

    Expert Comment

    if u have offline informations about the OS of your pc's in the domain!
    Do u have a software or hardware inventory tool like System Management Server (SMS) in use?!?!?

    As workarround you could write the script so, that only the pc's which are online are moved!
    And next time the script is executed it will move other pc's which are online

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do email signature updates give you a headache?

    Do you feel like you are constantly making changes to email signatures? Are the images not formatting how you want them to? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today.

    Some time ago I faced the need to use a uniform folder structure that spanned across numerous sites of an enterprise to be used as a common repository for the Software packages of the Configuration Manager 2007 infrastructure. Because the procedu…
    Welcome to my series of short tips on migrations. Whilst based on Microsoft migrations the same principles can be applied to any type of migration. My first tip is around source server preparation. No migration is an easy migration, there is a…
    In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
    Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now