I'd like to get help to create simple script. All it has to do is list sub-groups of groups, it shouldn't be even recursive and formatting for now is not that important.
I created script, but all it does, it writes lines with GROUP=$group
but not sub-groups.
It should write:
GROUP=$group
subgroup
subgroup
GROUP=$group
subgroup
...and so on.
Get-ADGroup -filter * -properties GroupCategory | FORMAT-Table -property name -hidetableheaders | Out-File -FilePath "D:\groups_list.txt"
$sourcepath = "D:\groups_list.txt"
$path = "D:\groups.txt"
foreach ($group in get-content $sourcepath) {
Out-File -FilePath $path -InputObject "GROUP= $group" -Append
Get-ADGroupMember $group | FORMAT-Table -property name -hidetableheaders | Out-File -FilePath $path -Append
}
If I do script without loop then everything is fine so I think there is some problem in loop which I don't know how to fix.
$group = "DEPARTMENT_Finance"
Out-File -FilePath $path -InputObject "GROUP= $group" -Append
Get-ADGroupMember $group | FORMAT-Table -property name -hidetableheaders | Out-File -FilePath $path -Append
Where is the mistake in the loop?