I'm working on creating a Powershell script that pulls nested distribution groups. My idea is that it will check the parent group for any children groups, then pull that group, rinse & repeat. I'm very new to PS to I might be getting hung up on something simple (hopefully).
Right now, I know how to pull what I want. I'm using:
$finallist = Get-DistributionGroupMember -Identity "DISTRO GROUP HERE" | Select Name, PrimarySMTPAddress
This works fine. I'm also able to do the following and have it add to the variable:
$finallist += Get-DistributionGroupMember -Identity "NEXT DISTRO" | Select Name, PrimarySMTPAddress
However, the problem that I'm having is that I cannot use += beginning with an empty initialized variable. At the start of the script, I of course initialize it by using $finallist = "". If I were to use the += version of the command immediately after, it results in a completely empty string. Making it equal to the first distribution group, then systematically adding each group after using a += works totally fine.
Hopefully I've described my issue adequately. If not, I'm happy to reiterate what I mean. Thanks a ton guys.