get members of group and update company field

this should be simple…but i’m having problems getting it done. I could do this if i exported to a csv and then imported that but i’d like to do this on the “fly” …plus i’d learn something new!

basically trying to get members of an ad group and update the company name field of each member, i’ve tried different ways of looping but cant get it to work. thanks for the help

here’s my last attempy

$users = Get-ADGroupMember -Identity testgroup -Recursive
where {$_.enabled -eq $true} | `
Set-ADUser -Identity $users.SamAccountName -Company "test company"

Is it really necessary to crosspost in more than one forum at the same time without even waiting some minutes for an answer?

https://social.technet.microsoft.com/Forums/de-DE/9783b18a-9409-468c-92bc-cf41804eb64b/update-company-field-of-group-members?forum=winserverpowershell

You could at least post a link to the crossposts to avoid people willing to help you spend some effort for nothing.

Get-ADGroupMember -Identity testgroup | %{Get-Aduser $_ | where {$.enabled -eq $true} | %{Set-Aduser $ -Company “Test Co.”}