locked
Compare ADObjects to Array RRS feed

  • Question

  • Hello,

    I am building a script which has two compare ADComputers with ADOU's. Whenever a Server is added in the domain i want to roll out an OU structure for that server. What would be the best possible way to Compare Servers with OU, and if there is a new server without an OU structure, Auto create the OU structure?

    Currently i tried:

    $Serverlist = Get-ADComputer -Filter * -SearchBase "$LocMemSer" -Searchscope 2 | Select Name

    $OUlist = Get-ADOrganizationalUnit -Filter * -SearchBase $LocMemGrp -Searchscope 1 | Select Name

    $Compared = Compare-Object $Serverlist $OUlist -IncludeEqual -ExcludeDifferent | Select-Object -ExpandProperty InputObject

    I am able to get the Name of the Servers and Base OU but now i have to compare them and roll out OU structures IF there is a new Server.

    How would i be able to do this?

    Monday, September 8, 2014 9:10 AM

Answers

  • Every server added to the domain requires his own OU. within those OU's i want to create OU's for specific groups, for example Local Administrator, User groups, etc.

    I know how to create the OU structure and groups. I want to know on which way i am able to compare all servers with the Server OU's, and then Create that OU structure for the servers WITHOUT its own structure.

    Comparing can be done with the Compare-Object, but i was wondering how i can use that output to create the OU structure. Hope its a bit clear now?

    • Marked as answer by Remco V Tuesday, September 9, 2014 12:13 PM
    Monday, September 8, 2014 11:09 AM

All replies

  • What are you asking?  What and why a new OU structure?

    Are you asking how to create a new OU? YOu will have to clarify the purpose for this.

    It sounds like you think that each server requires a new OU.  Generally we don't design AD like this.


    ¯\_(ツ)_/¯

    Monday, September 8, 2014 10:44 AM
  • Every server added to the domain requires his own OU. within those OU's i want to create OU's for specific groups, for example Local Administrator, User groups, etc.

    I know how to create the OU structure and groups. I want to know on which way i am able to compare all servers with the Server OU's, and then Create that OU structure for the servers WITHOUT its own structure.

    Comparing can be done with the Compare-Object, but i was wondering how i can use that output to create the OU structure. Hope its a bit clear now?

    • Marked as answer by Remco V Tuesday, September 9, 2014 12:13 PM
    Monday, September 8, 2014 11:09 AM
  • Why? Why would anyone do this.  It is not how we use OUs.  A server belongs to a control set established by policy or organizational structure.  Are you saying that every server in your organization has its own separate division/department/company structure?

    It is also not possible to understand what you are asking.  Are you asking how to determine if this is a new server?  How can a scrip decide what role a server is designed to play automatically?  This is something only humans can do.


    ¯\_(ツ)_/¯

    Monday, September 8, 2014 11:20 AM