I am trying to set up a PS script to add members if they are not part of a group and run it as a task. Can someone proof the code and provide feedback? Thanks.
$GROUP = 'CN=Group1,OU=SomeOU,DC=domain,DC=local'
Get-ADUser -Filter * -SearchBase "DC=domain,DC=local" -Properties MemberOf |
Where-Object {$_.MemberOf -notcontains $GROUP } |
ForEach-Object { Add-ADGroupMember -Identity $GROUP -Members $_ }