• Cloning an existing Security Group using Active Directory Powershell

    Yesterday I came across a recurring scenario where a distribution group existed for a user set, but no security group. As we needed a security group for publishing an application to this user-set via our App-V management servers, I was driven to develop a quick AD single PoSH single liner (not single pipeline, sadly). It copies all the user object members of one group into another. Here it is!

    $userstoclone = Get-ADGroup -filter {Name -like “Source Group”} | Get-ADGroupMember | Where-Object {$_.objectClass -eq “user”};ForEach ($user in $userstoclone){Add-ADGroupMember –Identity (Get-ADGroup -filter {Name -like “Target Group”}) -Members $user}

    It wouldn’t take a world of imagination to change the filters so it could copy computer objects, group objects, recurse somewhat deeper etc.