Hi and Welcome to Spiceworks - thanks for your first post here. Take a look at this: PLEASE READ BEFORE POSTING! Read if you're new to the PowerShell forum! which describes how we work here! I hope this is helpful.

Importing and exporting from Excel can be done using a CSV file. The CSV file is essentially a table of objects, preceded by a header to name each column. In the CSV, each row after the first represents an object occurrences properties. If you have a simple object, then exporting to CSV just gives you a row with the values as in the original object. WIth Complex objects, is ones where a property of the object is actually an object that has properties (which can be objects that have properties). An obvious example is (Get-Process | Select -skip 1 -First 1). Modules - Each process object has a Modules property. That property is an array of objects each with properties. This makes it more complex to build your excel spreadsheet. The problem is that when PowerShell takes an object array (ie what you get back from Get-ADGroup) it can not export the objects in the format you want.

SO, you can do this, but it is more wok. What you have to do is to run through the nested groups and build the relevant objects with the relevant properties via a set of next for each. It could certainly be done. You would need to Get the top level lists, and for each member spit out the users at that level, then get the level 1 groups. For each of those, spit out the users at that level and the Level 2 groups. FOr each of those, spit out the users at that level plus the level three groups. And for each of them spit out the users at level 4.

You can start by getting the objects at the top level:

$ArrayOfUsers = @()   # you ad to this
Function Add-User { <adds the user to the array}  # fill in the blanks
$TopLevel = Get-AdObject -Filter * -SearchScope OneLevel -SearchBase 'ou=cookhamhq,dc=cookham,dc=net'
Foreach ($Obj in $TopLevel) 
  If (! (object is a user or a group) continue # skip over this
  If <object is user>  {add-uuser $obj -Level 1}     # add this user to the array of user
  Else  {   #here to process a level 1 group
    $Level2objes = Get-Adobject -Filter * =searchscope ONeLevel -Searchbase <work it out from $obj> 
    Foreach (L2obj in $Level2objs)
     -skip over non group/users
     =add a L2 user> 
     <process L2 groups>
    etc

I hope this gets you started.

I haven’t looked closely enough, but you might be able to get some help from the ImportExcel module which you can download from the PS Gallery. See PowerShell Gallery | ImportExcel 5.4.2

Have a go, post what you come up with for more help.

1 Spice up