• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 287
  • Last Modified:

Os wise sorting of all machines in different Ou's

Hi,

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.

regards
Sharath
0
bsharath
Asked:
bsharath
  • 3
  • 3
1 Solution
 
merowingerCommented:
0
 
bsharathAuthor Commented:
That is a different Q.In this Q i need to sort by OS.
0
 
merowingerCommented:
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)
Const ADS_SCOPE_SUBTREE = 2
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

            objRecordSet.MoveFirst

            Do Until objRecordSet.EOF
               strADsPath = objRecordSet.Fields("ADsPath").Value
               objOU.MoveHere strADsPath, vbNullString
               objRecordSet.MoveNext
            Loop
   else
      'Do Nothing
   End If
Next
loop
'-----------------------------------------------------------------------------------------------------------
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
jcwebholeCommented:
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)
0
 
bsharathAuthor Commented:
What does this script above do?

I tried this and no changes took place.I changed the OU name in the script too.
0
 
bsharathAuthor Commented:
Any way to move even when the machines are offline.?
0
 
merowingerCommented:
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
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now